AnsweredAssumed Answered

Save As PDF macro, how to save one or two directories back?

Question asked by Shaun Jalbert on May 12, 2015
Latest reply on Jan 31, 2019 by Deepak Gupta

I found a macro online for performing a "save as PDF", but it saves the file under the current working directory. The way our file structure is set up, we have a folder named "PDF" typically one to two directories back. Is there a way to manipulate the existing code so it drops the files under the correct directory?

 

Here's the existing code:

 

Sub main()

       

 

    Set swApp = Application.SldWorks

 

    Set swModel = swApp.ActiveDoc

   

 

    ' Strip off SolidWorks drawing file extension (.slddrw)

 

    ' and add DXF file extension (.dxf)

 

    sPathName = swModel.GetPathName

 

    sPathName = Left(sPathName, Len(sPathName) - 6)

 

    sPathName = sPathName + "pdf"

 

   

    ' Show current settings

 

    Debug.Print "DxfMapping             = " & swApp.GetUserPreferenceToggle(swDxfMapping)

 

    Debug.Print "DXFDontShowMap         = " & swApp.GetUserPreferenceToggle(swDXFDontShowMap)

   

 

    Debug.Print "DxfVersion             = " & swApp.GetUserPreferenceIntegerValue(swDxfVersion)

 

    Debug.Print "DxfOutputFonts         = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputFonts)

 

    Debug.Print "DxfMappingFileIndex    = " & swApp.GetUserPreferenceIntegerValue(swDxfMappingFileIndex)

 

    Debug.Print "DxfOutputLineStyles    = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputLineStyles)

 

    Debug.Print "DxfOutputNoScale       = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputNoScale)

       

 

    Debug.Print "DxfMappingFiles        = " & swApp.GetUserPreferenceStringListValue(swDxfMappingFiles)

 

   

    Debug.Print "DxfOutputScaleFactor   = " & swApp.GetUserPreferenceDoubleValue(swDxfOutputScaleFactor)

 

    Debug.Print ""

       

 

    ' Turn off showing of map

 

    bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)

 

    Debug.Print "bShowMap = " & bShowMap

   

    swApp.SetUserPreferenceToggle swDXFDontShowMap, False

 

       

    bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)

    Beep

 

    If bRet = False Then

 

        nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)

 

    End If

 

    ' Restore old setting

 

    swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap

 

End Sub

 

'----------------------------------------------

Outcomes