Macro won't work unless opened/closed first.

I have a macro I created that saves a drawing as a PDF with the Revision added on the end.  It works fine but will only work if I first open it in the VBA editor then close it (not even saving or touching anything), then it runs just fine.  Any help is appreciated.  Below is the macro:

Option Explicit

Dim swApp           As SldWorks.SldWorks

Dim swModel         As SldWorks.ModelDoc2

Dim PDFFileName     As String

Dim PDFPath         As String

Dim Revision        As String

 

Sub Main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

'Get Revision

Revision = swModel.CustomInfo("Revision")

 

'Set Path

PDFPath = PDFPath & "C:\\Users\\mzellmer\\Desktop\\MZ\\Temp"

'Set File Name

PDFFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\\") + 1)

PDFFileName = Left(PDFFileName, InStrRev(PDFFileName, ".") - 1) & " Rev_" & Revision & ".PDF"

 

'Save File

swModel.SaveAs (PDFPath & "\\" & PDFFileName)

 

End Sub

SolidworksApi macros