Run Inventor Macro from Excel

Run Inventor Macro from Excel

Anonymous
Not applicable
2,625 Views
3 Replies
Message 1 of 4

Run Inventor Macro from Excel

Anonymous
Not applicable

Hello there,

 

I'm trying to launch an inventor Macro via an Excel Command Button.

I've managed to open the inveotor document in which all the macros are. Now all left to do is to run one macro.

 

I tried for hours and, sadly, I'm not able to get this to work.

 

Here is what I have:

 

Public Sub CommandButton1_Click()

    Dim InvFilename As String
    
    CommandButton1.Caption = "hello there."

    InvFilename = "my_path"

    InvFilename = "C:\Program Files\Autodesk\Inventor 2017\Bin\inventor.exe """ & InvFilename & """"

    Call Shell(InvFilename, 1)
    

    Dim inv As Object
    Set inv = CreateObject("Inventor.Application")
    inv.Run "Module1.test"                              '<-----------------------ERROR 438

End Sub

 

This is the Error Message I get: Object doesn't support this property or method. 438

 

Can someone please help me?

 

-Jake

0 Likes
Accepted solutions (1)
2,626 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor
Accepted solution
invApp.VBAProjects(1).InventorVBAComponents("AppEventController").InventorVBAMembers("StartEvent").Execute

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 4

Anonymous
Not applicable

Thanks for your reply.

 

I just managed to do it myself via the following code. I guess your way is more elegant.

 

    Dim invApp As inventor.Application
    Set invApp = GetObject(, "Inventor.Application")

    Dim invVBAProject As InventorVBAProject
    Set invVBAProject = invApp.VBAProjects.Item(2)

    Dim invModule As InventorVBAComponent
    Set invModule = invVBAProject.InventorVBAComponents.Item("Main")

    Dim invSub As InventorVBAMember
    Set invSub = invModule.InventorVBAMembers.Item("test")

    invSub.Execute

 

If anyone ever wants to do the same thing as I did:

It doesn't work to open the Inventor Project and immediatley execute the macro, so it isn't possible to use just one macro. The Execution has to start when inventor is fully loaded not a second before, otherwise this Error appears "ActiveX Component Can't Create Object (429)".

 I simply use one button to start inventor and a second one to trigger the macro.

 

Maybe it helps someone

-Jake

0 Likes
Message 4 of 4

MechMachineMan
Advisor
Advisor
You can do it all in one by having a wait loop to delay the code until the
invApp.Ready = True

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes