Excel VBA to Save Copy As

Excel VBA to Save Copy As

Anonymous
Not applicable
3,675 Views
8 Replies
Message 1 of 9

Excel VBA to Save Copy As

Anonymous
Not applicable

Hi all,

 

I'm trying to use Excel VBA to call Inventor to open an idw drawing, then Save Copy As dwg for AutoCAD. I found, in VBA, the class Document that has a SaveAs method but when I run the code it would not compile, giving me the message "Object doesn't support this property or method".

 

Can anyone point me to the right direction? My main goal is to use Excel VBA to save an idw drawing to an AutoCAD dwg file as a new copy. Thanks.


Danny

0 Likes
Accepted solutions (1)
3,676 Views
8 Replies
Replies (8)
Message 2 of 9

schmidmi
Autodesk
Autodesk

Hi Danny -

 

Thank you for your question.  I was able to create a sample VBA script that takes known *.dwg file and save it as a *.idw.  Take a look at the example for any differences there are between it and yours.

 

Public Sub SaveAsSample()
    
    Dim sFilePath As String
    sFilePath = "C:\Temp\Drawing1.dwg"
Dim oDoc As Document Set oDoc = ThisApplication.Documents.Open(sFilePath) Dim sFilePathCopy As String sFilePathCopy = "C:\Temp\Drawing1_copy.idw" Call oDoc.SaveAs(sFilePathCopy, True) oDoc.Close End Sub

Let me know if you continue to have trouble.

 

Thanks!


Michael Schmidt, Principal Engineer
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi Michael, thank you for your reply. I'm sorry I have been late in trying this. I actually have stopped checking the message box a day after I posted the question, thinking that no one had an answer.

 

What I needed was actually the other way around. I would like to have VBA (from Excel) open an idw and SaveCopy as dwg.

 

Nevertheless, I tried your solution to see if I can run it. When I ran it, I received an error in the Set oDoc line (underlined below) saying ActiveX component can't create object. Do you know what it means and how to fix it? Thanks again.

 

Public Sub SaveAsSample()
   
    Dim sFilePath As String
    sFilePath = "C:\Inventor Tutorial\GEMMA MEDWAY MODEL\2000 - Plenum Drive\Drawings\Drawing1.dwg"

    Dim oDoc As Document
    Set oDoc = ThisApplication.Documents.Open(sFilePath)
   
    Dim sFilePathCopy As String
    sFilePathCopy = "C:\Temp\Drawing1_copy.idw"
   
    Call oDoc.SaveAs(sFilePathCopy, True)
   
    oDoc.Close
 
End Sub

0 Likes
Message 4 of 9

MechMachineMan
Advisor
Advisor

Have you properly connected to inventor?

 

ie;

 

Dim oInvApp As New Inventor.Application

Set oInvApp = GetObject("", "Inventor.Application")

 

'Do Things

 

oInvApp.Quit

Set oInvApp = Nothing


--------------------------------------
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
Message 5 of 9

Anonymous
Not applicable

Hi Justin,

 

I did not include the code you proposed at first. After I added it, I am still having the same issue.

 

 

Public Sub SaveAsSample()

 

'Dim oInvApp As New Inventor.Application I disabled this and replaced with the line below because VBA says I'm using "New" improperly
Dim oInvApp As Object

Set oInvApp = GetObject("", "Inventor.Application")
oInvApp.Visible = True

Dim sFilePath As String
sFilePath = "C:\Inventor Tutorial\GEMMA MEDWAY MODEL\2000 - Plenum Drive\Drawings\Drawing1.dwg"

Dim oDoc As Document
Set oDoc = ThisApplication.Documents.Open(sFilePath) 'This is where I get the runtime error 429 --> ActiveX component can't create object
   
Dim sFilePathCopy As String
sFilePathCopy = "C:\Temp\Drawing1_copy.idw"
   
Call oDoc.SaveAs(sFilePathCopy, True)
   
oDoc.Close

oInvApp.Quit

Set oInvApp = Nothing

 

End Sub

 

Any help would be appreciated. Thank you.

 

Danny Tan

0 Likes
Message 6 of 9

MechMachineMan
Advisor
Advisor
Change this ThisApplication to oInvApp.

Opening the app doesn't do much if you don't reference the object when you
actually need to use it. Ha

--------------------------------------
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
Message 7 of 9

MechMachineMan
Advisor
Advisor
Change this ThisApplication to oInvApp.

Opening the app doesn't do much if you don't reference the object when you
actually need to use it. Ha

--------------------------------------
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
Message 8 of 9

MechMachineMan
Advisor
Advisor
Accepted solution
Change this ThisApplication to oInvApp.

Opening the app doesn't do much if you don't reference the object when you
actually need to use it. Ha

--------------------------------------
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 9 of 9

Anonymous
Not applicable

Hello Justin,

 

I've tried your solution; it works. Thank you. Sorry for the late reply; I had wanted to roll out the solution to my team and make sure it works before accepting as solution and closing out this topic.

 

Thanks again, and Happy Holidays!

 

Danny

0 Likes