我寫了一段呼叫Excel的程式:
Private Sub Command1_Click()
Dim objExcel As Object, objWorkbook As Object, objWorksheet As Object
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel.Visible = True
objWorksheet.Cells(1, 1) = "大家好"
Range("A2:E2").Select
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
End Sub
當我執行時,第一次沒有問題,可是當我關閉Excel,再按一次時,
VB發出訊息:
執行階段錯誤'1004':
'Range'方法('_Global'物件)失敗
怎麼辦?請問如何處理?