AnsweredAssumed Answered

Macro troubleshooting - opening a part from specified location

Question asked by Eric Frissell on Sep 5, 2019
Latest reply on Sep 6, 2019 by Eric Frissell

Hi guys, looking for a little troubleshooting help with a macro that I wrote this morning that I can't seem to get to work.  I've played around with it for a few hours and tried to get it close to the macro at 2017 SOLIDWORKS API Help - Open Document Silently Example (VBA) without completely blowing away everything I've done but it just won't work.

My intentions are pretty simple - to write a macro that collects some project information, opens a template, modifies the custom properties, then saves it out, but it's not opening the file.  Thanks in advance

 

Sub main()

'Template Location
Const File_Location As String = "C:\TAW_CE\Library\design library\Labels\Template - Nameplate.SLDPRT"


Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc

'Variables
Dim Project_Title As String
Dim Part_Number As Long
Dim Project_Number As Long
Dim MFG_Date As Variant
Dim Nameplate_AX As Long

'Errors
Dim nDocType As Long
Dim nErrors As Long
Dim nWarnings As Long


Set swApp = CreateObject("SldWorks.Application")

Pause = MsgBox("Click Okay to continue once an AX number is created", vbOKOnly)

Nameplate_AX = InputBox("AX Number for nameplate")
'Project_Number = InputBox("What is the 8 digit project number?")
'Project_Title = InputBox("What is the title of the project? Limit characters to 24")
'Part_Number = InputBox("Part or Assembly number nameplate is attached to")
'MFG_Date = InputBox("What is the date of manufacture")

Debug.Print File_Location; " is the template location"
Debug.Print Nameplate_AX; " Is the AX number of the nameplate"
'Debug.Print Project_Title; " Is the project name"
'Debug.Print Part_Number; " Is the Part number"
'Debug.Print MFG_Date; " is the date of manufacture"

 

Set swDoc = swApp.OpenDoc6(File_Location, nDocType, swOpenDocOptions_Silent, "", nErrors, nWarnings)


Debug.Print "File = " & swDoc.GetPathName

Debug.Print " Error (0 = no errors) = " & nErrors

Debug.Print " Warnings (2 = document is read-only) = " & nWarnings


End Sub

Outcomes