Hi,
I have a following code which is not allowing me to save file to PDF. I was wondering if someone can help me with it.
This code, checks if a folder exists and if not it creates the folder, add revision number to the file name. I will appreciate if someone can help me in getting the save as pdf part correct.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.ModelDoc
Dim Filepath As String
Dim FileName As String
Dim PDFFileName As String
Dim InterPath As String
Dim PDFPath As String
Dim oFolder As String
Dim Revision As String
Dim boolstatus As Boolean
Dim PDFPathandName As String
Sub main()
Set swApp = Application.SldWorks
'Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swDraw = swApp.ActiveDoc
'Check to see if a drawing is loaded.
If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then
swApp.SendMsgToUser ("To be used for drawings only, Open a drawing first and then TRY!")
'If no model currently loaded, then exit
Exit Sub
End If
Filepath = swDraw.GetPathName
InterPath = Left(Filepath, Len(Filepath) - 31)
MsgBox (InterPath)
PDFPath = InterPath & "01 Released Drawings" & "\\PDFs"
MsgBox (PDFPath)
Revision = swDraw.CustomInfo("Revision")
FileName = swDraw.GetPathName
PDFFileName = Left(FileName, Len(FileName) - 7) & "-R" & Revision & ".pdf"
MsgBox (PDFFileName)
oFolder = PDFPath
If Dir(oFolder, vbDirectory) = vbNullString Then
MkDir (oFolder)
MsgBox "Folder Created"
End If
PDFPathandName = PDFPath & "/" & PDFFileName
swDraw.SaveAs (PDFPathandName & ".PDF")
End Sub
SolidworksApi macros