Hi,
I'm using a code from Keith Rice to save drawings off as PDF's in a specific location on our network.
An issue we have run into is when the file we are trying to save as pdf was opened through the network drive we get "run-time error 52 bad filename or number" on line 45 of the code.
\\XXXX\Design\DRAWINGS CONSTRUCTION\0-2018\Job Name\SolidWorks Files\Drawings
vs
N:\DRAWINGS CONSTRUCTION\0-2018\Job Name\SolidWorks Files\Drawings - This way runs the macro correctly.
From my searches it looks as though the \\xxxx name isn't a valid name.We'd like to be able to run this macro from either location, is this possible?
Thanks for any help.
Const NEW_EXTENSION As String = "PDF"
Const FOLDER_NAME As String = "Released Drawings"
Sub main()
If FOLDER_NAME = Empty Then Exit Sub
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Create new file name
Dim strModelPath As String
Dim strSavePath As String
Dim strSaveFolder As String
Dim strFileName As String
Dim vSplit As Variant
strModelPath = swModel.GetPathName
If swModel.GetPathName = Empty Then
swApp.SendMsgToUser "Please save model."
Exit Sub
End If
strFileName = Right(strModelPath, _
Len(strModelPath) - InStrRev(strModelPath, "\"))
vSplit = Split(strFileName, ".")
strFileName = vSplit(0) & " REV_" & swModel.CustomInfo2("", "Revision") & "." & NEW_EXTENSION
' Create new directory
vSplit = Split(strModelPath, "\")
Dim intDirAbove As Integer
Dim i As Integer
Dim bFound As Boolean
bFound = False
For i = 0 To UBound(vSplit) - intDirAbove
strSaveFolder = strSaveFolder & vSplit(i) & "\"
If Dir(strSaveFolder & FOLDER_NAME, vbDirectory) <> Empty Then
bFound = True
Exit For
End If
Next i
If bFound = False Then
swApp.SendMsgToUser "Failed to find correct folder."
Exit Sub
End If
strSavePath = strSaveFolder & FOLDER_NAME & "\" & strFileName
Debug.Print "Original path: " & strModelPath
Debug.Print "New save path: " & strSavePath
' Save
bRet = swModel.Extension.SaveAs(strSavePath, swSaveAsCurrentVersion, _
swSaveAsOptions_Silent, Nothing, Empty, Empty)
If bRet = False Then swApp.SendMsgToUser "Problems saving file. Check if file is open"
End Sub