Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
mrako
in reply to: WCrihfield

Hi WCrihfield

 

Your code also doesn't work, it's still a bug

Private Sub TestExcel2()
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True

Dim oWB As Workbook ''Workbook
If oExcel.Workbooks.Count = 0 Then
    Set oWB = oExcel.Workbooks.Add()
Else
    Set oWB = oExcel.Workbooks.Item(1)
    'or
    'oWB = oExcel.ActiveWorkbook
End If

Dim oWS As WorkSheet
If oWB.Worksheets.Count = 0 Then
    oWS = oWB.Worksheets.Add
Else
    oWS = oWB.ActiveSheet
    'or
    'oWS = oWB.Worksheets..Item(1)
End If

oWS.Cells(1, 1).Value = "Works !"

oWB.SaveAs ("c:\Temp\test.xls") 'Save excel
oExcel.Quit
oWS = Nothing
oWB = Nothing
oExcel = Nothing
End Sub

After  command  

Set oWB = oExcel.Workbooks.Add()

in watch window I see  workbooks.count  changed from 0 to 1

and show error and

oWB = Nothing  !!

Screenshot_3.png

 

I note that on a PC where the Inventor2021 + excel2007 code works
does not work on PCs where it is Inventor 2021 + excel 2016

 

Sorry about my English

 

Thanks