有一个调用Excel的过程如下:
sub eee()
On Error Resume Next
dim ex as Object
dim sheet as object
set ex = GetOjbect(, "Excel.Application")
if Err 0 then
set ex = CreateObject("Excel.Application")
Err.claer
end if
ex.WorkSheets("Sheet1").Activate
end sub
系统使用 2002、Excel 2003 sp2
过程执行到ex.WorkSheets("Sheet1").Activate一句时总是提示"对象变量或With块变量未设置"的错误,检查之后发现ex并未获得Excel的引用不知道为什么!
Dim strDestination As String
Dim xlApp As Excel.Application
Dim xlBook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application ''激活EXCEL应用程序
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False '隐藏EXCEL应用程序窗口
Set xlBook = xlApp.Workbooks.Open(strDestination) '打开工作簿,strDestination为一个EXCEL报表文件
Set xlSheet = xlBook.Worksheets(1) '设定工作表
'现在就可以直接访问当前活动的工作簿中的“Sheet1”工作表
xlBook.Save '保存文件
xlApp.Quit '退出EXCEL