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

I'm using Inventor Professional 2021.1 and Office 365 (the Account info within my Excel application says Microsoft Office Professional Plus 2019), and I'm using Windows 10 Enterprise.

Here is a sample VBA macro I used to test with, and it works for me without any errors.

 

Sub UseExcel()
    'Create New instance of the Excel application
    Dim oExcel As Excel.Application
    Set oExcel = New Excel.Application
    oExcel.DisplayAlerts = False
    oExcel.Visible = True
    
    'Get a Workbook
    Dim oWB As Excel.Workbook
    If oExcel.Workbooks.Count = 0 Then
        Set oWB = oExcel.Workbooks.Add
    Else
        Set oWB = oExcel.ActiveWorkbook
        'or
        'Set oWB = oExcel.Workbooks.Item(1)
    End If
    'Set oWB = oExcel.Workbooks.Open("C:\Temp\Test.xlsx")
    
    'Get a Worksheet
    Dim oWS As Excel.WorkSheet
    If oWB.Worksheets.Count = 0 Then
        Set oWS = oWB.Worksheets.Add
    Else
        Set oWS = oWB.ActiveSheet
        'or
        'Set oWS = oWB.Worksheets.Item(1)
    End If
    'Set oWS = oWB.Worksheets.Item("Sheet1")
    
    'Work with Cells by Row Index, then Column Index
    Dim oCells As Excel.Range
    Set oCells = oWS.cells
    'Create column headers
    'First number is Row index, second number is Column Index
    oCells.Item(1, 1).Value = "FIRST"
    oCells.Item(1, 2).Value = "LAST"
    oCells.Item(1, 3).Value = "E-MAIL"
    
    'Make All Columns AutoFit widths to fit contents
    oWS.Columns.AutoFit
    
    'oWB.Save
    oWB.SaveAs ("C:\Temp\Test.xlsx")
    'oWB.Close
    'oExcel.Quit
End Sub

 

So if this isn't working for you, it would seem there is something going on other than just coding technique that's preventing this from working.

Is it possible your Excel application has some security settings preventing it from being manipulated by code.

I wander if the setting within Inventor's Tool tab > Options panel > iLogic Configuration > Excel Options setting.  I have mine set to "COM", but I was under the impression this only effected the GoExcel stuff in iLogic.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' :thumbs_up:.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)