其他分享
首页 > 其他分享> > 其他VBA相关语句

其他VBA相关语句

作者:互联网

'自动获取已使用区域
'col = Selection.Column '获取表格开始单元格的列数
'Row = Selection.Row '获取表格开始单元格的行数

'ActiveThisWorkbook.Sheets(1).Select

ActiveSheet.UsedRange.Select

Sheets.Add After:=Sheets(Sheets.Count)

 

'For i = 2 To Sheets.Count

'Sheets(i).Name = Sheets(1).Cells(D6, 1).Value

'Sheets(i).Name = ThisWorkbook.Sheets("模板").Range("D6") & "年" & ThisWorkbook.Sheets("模板").Range("G6") & "月"

'Set NewWorksheet = Worksheets.Add '建立新表

Set NewWorksheet = Sheets(Sheets.Count)

NewWorksheet.Name = ThisWorkbook.Sheets("考勤登记").Range("D6") & "年" & ThisWorkbook.Sheets("考勤登记").Range("G6") & "月"
NewWorksheet.Range("a1:aq26") = arr

'ThisWorkbook.Sheets(i).Range("a1:aq26") = arr

 

 


'ActiveSheet.UsedRange.Select

'ActiveSheet.Range("a5:aq26") = arr

NewWorksheet.Select
ActiveSheet.UsedRange.Select

'Selection.Columns.AutoFit '设置单元格格式

ActiveSheet.Range("a7:aq26").Font.Name = "宋体"
ActiveSheet.Range("a7:aq26").Font.Size = "8"

'Range("A3") = Format(date_test, "mm/dd hh:mm")

ActiveSheet.Range("a7:aq26").ColumnWidth = 4.5

'ActiveSheet.Range("a7:aq26").ColumnWidth = 4

ActiveSheet.Range("a8:aq8").NumberFormatLocal = "aaaa" ' 格式化星期
ActiveSheet.Range("a7:aq7").NumberFormatLocal = "d" '格式化天

ActiveSheet.Range("a7:aq7").NumberFormatLocal = "d"

ActiveSheet.Range("D6").Interior.ColorIndex = 6 ' 背景的颜色为6 黄色
ActiveSheet.Range("G6").Interior.ColorIndex = 6 ' 背景的颜色为3 红色

ActiveSheet.Range("B7:AF26").Borders.ColorIndex = 5 '背景的颜色为蓝色

ActiveSheet.Range("AH7:AQ26").Borders.ColorIndex = 3 '背景的颜色为红色色


'NewWorksheet.Select
'NewWorksheet.Visible = 0

ThisWorkbook.Sheets("考勤登记").Select

'NewWorksheet.visibe = 0

'Selection.FormatConditions(1).Font.ColorIndex
'ActiveSheet.UsedRange.Select
'Borders(xlEdgeBottom).ColorIndex 边框颜色

'Cells(1, 1).Font.ColorIndex = 3 '字的颜色号为3 红色
'Cells(1, 1).Interior.ColorIndex = 3 ' 背景的颜色为3 红色
'Cells(2, 1).Font.Color = RGB(0, 255, 0) '字的颜色绿色
'Cells(2, 1).Interior.Color = RGB(0, 0, 255) '背景的颜色蓝色

'ThisWorkbook.Activate

'ActiveSheet.UsedRange.Select '选择已经使用的区域
'Selection.Columns.AutoFit '自动调整选择列的列宽

'Workbooks.Add '新建工作薄。
'With ActiveWorkbook '面向活动工作薄(新工作薄)
'ThisWorkbook.ActiveSheet.Copy Before:=.Sheets(1)


'格式化单元格

NewWorksheet.Visible = 0


MsgBox "创建工作表完成"

End Sub


Sub 查询() ' 经典!!!!!

Dim arr
'Dim i As Long

For n = Worksheets.Count To 1 Step -1

If Worksheets(n).Name = Sheets("考勤查询表").Range("D6") & "年" & ThisWorkbook.Sheets("考勤查询表").Range("G6") & "月" Then '( 这里的sh区分大小写)

'Set arr =

Worksheets(n).Range("a7:aq26").Copy Destination:=Sheets("考勤查询表").Range("A7:aq26")

ActiveSheet.UsedRange.Select

'Sheets("考勤查询表").Range("a1:aq26") = arr

 


End If

Next

MsgBox "查询完成"

End Sub
'
''pppp
'
'ThisWorkbook.Sheets("考勤模板").Select
'ActiveSheet.UsedRange.Select
'
'arr = ThisWorkbook.Sheets("考勤模板").Range("a1:aq26")

 

'自动获取已使用区域
'col = Selection.Column '获取表格开始单元格的列数
'Row = Selection.Row '获取表格开始单元格的行数

'ActiveThisWorkbook.Sheets(1).Select

'ActiveSheet.UsedRange.Select
'
'Sheets.Add After:=Sheets(Sheets.Count)

 

'For i = 2 To Sheets.Count

'Sheets(i).Name = Sheets(1).Cells(D6, 1).Value

'Sheets(i).Name = ThisWorkbook.Sheets("模板").Range("D6") & "年" & ThisWorkbook.Sheets("模板").Range("G6") & "月"

'Set NewWorksheet = Worksheets.Add '建立新表

'Set NewWorksheet = Sheets(Sheets.Count)

'NewWorksheet.Name = ThisWorkbook.Sheets("考勤模板").Range("D6") & "年" & ThisWorkbook.Sheets("考勤模板").Range("G6") & "月"
'NewWorksheet.Range("a1:aq26") = arr

'ThisWorkbook.Sheets(i).Range("a1:aq26") = arr

 

 


'ActiveSheet.UsedRange.Select

'ActiveSheet.Range("a5:aq26") = arr
'
'NewWorksheet.Select
'ActiveSheet.UsedRange.Select
'
''Selection.Columns.AutoFit '设置单元格格式
'
'ActiveSheet.Range("a7:aq26").Font.Name = "宋体"
'ActiveSheet.Range("a7:aq26").Font.Size = "8"

''Range("A3") = Format(date_test, "mm/dd hh:mm")
'
'ActiveSheet.Range("a7:aq26").ColumnWidth = 4.5
'
''ActiveSheet.Range("a7:aq26").ColumnWidth = 4
'
'ActiveSheet.Range("a8:aq8").NumberFormatLocal = "aaaa" ' 格式化星期
'ActiveSheet.Range("a7:aq7").NumberFormatLocal = "d" '格式化天
'
'ActiveSheet.Range("a7:aq7").NumberFormatLocal = "d"
'
'ActiveSheet.Range("D6").Interior.ColorIndex = 6 ' 背景的颜色为6 黄色
'ActiveSheet.Range("G6").Interior.ColorIndex = 6 ' 背景的颜色为3 红色
'
'ActiveSheet.Range("B7:AF26").Borders.ColorIndex = 5 '背景的颜色为蓝色
'
'ActiveSheet.Range("AH7:AQ26").Borders.ColorIndex = 3 '背景的颜色为红色色
'
'
''NewWorksheet.Select
''NewWorksheet.Visible = 0
'
'ThisWorkbook.Sheets("考勤模板").Select

'NewWorksheet.visibe = 0

'Selection.FormatConditions(1).Font.ColorIndex
'ActiveSheet.UsedRange.Select
'Borders(xlEdgeBottom).ColorIndex 边框颜色

'Cells(1, 1).Font.ColorIndex = 3 '字的颜色号为3 红色
'Cells(1, 1).Interior.ColorIndex = 3 ' 背景的颜色为3 红色
'Cells(2, 1).Font.Color = RGB(0, 255, 0) '字的颜色绿色
'Cells(2, 1).Interior.Color = RGB(0, 0, 255) '背景的颜色蓝色

'ThisWorkbook.Activate

'ActiveSheet.UsedRange.Select '选择已经使用的区域
'Selection.Columns.AutoFit '自动调整选择列的列宽

'Workbooks.Add '新建工作薄。
'With ActiveWorkbook '面向活动工作薄(新工作薄)
'ThisWorkbook.ActiveSheet.Copy Before:=.Sheets(1)


'格式化单元格

' NewWorksheet.Visible = 0

标签:语句,ThisWorkbook,VBA,ActiveSheet,Range,aq26,Sheets,相关,Select
来源: https://www.cnblogs.com/xyq530/p/15334045.html