[求助]用VBA对EXCEL编程时遇到的问题,请教!
小弟用EXCEL自带的VBA对前台进行编程,
在VBA界面中插入了一个模块,在模块中编写代码:
Public xls As New Excel.Application
Public xlbook As Excel.Workbook
Public xlsheet As Excel.Worksheet
--------------------------------------------------------------------
Sub HH()
Set xls = GetObject(, "Excel.Application")
Set xlbook = xls.ActiveWorkbook
Set xlsheet = xlbook.Sheets("Sheet1")
xlsheet.Cells(1, 1) = "aa"
xlsheet.Cells(1, 2) = "bb"
xlsheet.Cells(2, 1) = "cc"
xlsheet.Cells(2, 2) = "dd"
Set xlsheet = Nothing
Set xlbook = Nothing
Set xls = Nothing
End Sub
运行后有错误提示,说 xlbook.Sheets("Sheet1")对象变量或with块变量未设置。
小弟初学乍练不清楚意思,请各位高人指教!
谢谢!