J
Jesper
I'm doing some automation to Excel from Access with the following.
This code fails exactly every other time I run it and works fine every other
time.
Dim objExcelApp As Object 'late binding
Dim objExcelDoc As Object 'late binding
Dim v(50) As String
Set objExcelApp = CreateObject("excel.application") 'late binding
Set objExcelDoc = objExcelApp.Workbooks.Add
objExcelApp.Visible = True
'fill array
For i = LBound(v) To UBound(v)
v(i) = CStr(Int(Rnd() * 100))
Next
objExcelDoc.Sheets(1).Range(Cells(1, 1), Cells(1, UBound(v))) = v
Set objExcelDoc = Nothing
Set objExcelApp = Nothing
When it fails I get:
Runtime error 1004
Method 'Cells' og object '_Global' failed
and it fails at this line:
objExcelDoc.Sheets(1).Range(Cells(1, 1), Cells(1, UBound(v))) = v
Does anyeone have any idea what's going on here?
Am I terminating Excel properly?
Jesper, Denmark
This code fails exactly every other time I run it and works fine every other
time.
Dim objExcelApp As Object 'late binding
Dim objExcelDoc As Object 'late binding
Dim v(50) As String
Set objExcelApp = CreateObject("excel.application") 'late binding
Set objExcelDoc = objExcelApp.Workbooks.Add
objExcelApp.Visible = True
'fill array
For i = LBound(v) To UBound(v)
v(i) = CStr(Int(Rnd() * 100))
Next
objExcelDoc.Sheets(1).Range(Cells(1, 1), Cells(1, UBound(v))) = v
Set objExcelDoc = Nothing
Set objExcelApp = Nothing
When it fails I get:
Runtime error 1004
Method 'Cells' og object '_Global' failed
and it fails at this line:
objExcelDoc.Sheets(1).Range(Cells(1, 1), Cells(1, UBound(v))) = v
Does anyeone have any idea what's going on here?
Am I terminating Excel properly?
Jesper, Denmark