AnsweredAssumed Answered

How to make a message to the user: "Please first save the file." in VBA macro?

Question asked by Bobo Zhelev on Aug 27, 2014
Latest reply on Aug 28, 2014 by Deepak Gupta

Hello,
I have a question concerning the following simple macro. Macro is used to convert PDF files into solidvorks document. Macro works fine, but if the file is not saved shows an error message. I would like if the file is not saved to show a message to the user: "Please first save the file." After recording the macro file to continue.
Thanks in advance for your help.

 

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim lErrors As Long

Dim lWarnings As Long

Dim FileName As Variant

Dim Path As String

 

Sub main()

 

Set swApp = Application.SldWorks

 

Set swModel = swApp.ActiveDoc

 

If swModel Is Nothing Then

 

    MsgBox "Please first open solidvorks file."

 

    Exit Sub

 

End If

 

Dim exportData As SldWorks.ExportPdfData: Set exportData = swApp.GetExportFileData(swExportPdfData)

 

exportData.ExportAs3D = True

 

Path = "D:\"

 

FileName = swModel.GetTitle

 

FileName = Left(FileName, Len(FileName) - 7)

 

FileName = Path & FileName & ".pdf"

 

swModel.Extension.SaveAs FileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, exportData, lErrors, lWarnings

 

End Sub

Outcomes