range\worksheet\workbook\application
1.application.cells属性
Sub application示例()
dim i as integer
'aplication.cells属性:当前正处于激活状态的工作表的单元格'
For i = 1 to 5
application.cells(i,5) = 7
Next
End Sub
2.application.activeworkbook属性案例
application.activeworkbook
application.activeworksheet
option explicit
sub 活动工作簿()
dim w1 as workbook
dim w2 as workbook
'从一开始就定义 w1为活动的单元格'
set w1 = application.activeworkbooks
set w2 = workbooks.add
w1.worksheet(1).cells(2,6) = "早晨的奶酪很好吃"
w2.workshhet(1).cells(3,4) ="新文件"
end sub
3.application.worksheetfunction.公式名称
例如:求某个range的最大值可以使用application.worksheetfunction.max(range(i))
注:cos()属于系统函数 所以不存在公式中
option explicition
sub 求最大值()
dim i
i = application.worksheetfunction.max(range("B2:D7"))
cells(9,4) = i
end sub
4.application.displayalerts:是否显示excel警示框
option explicit
sub 保存工作簿示例()
dim w as workbook
set w = workbooks.add
w.worksheets(1).cells(1,6) = "随便写写"
application.displayalerts = false
w.saveas("数据.xlsx")
application.displayalerts = true
w.close
end sub