4 Replies Latest reply on Apr 14, 2017 4:30 AM by Deepak Gupta

    Macro to save a dwg to a different folder.

    Dan Enns

      We have a macro that will save our drawing as a DWG in the folder that the drawing is saved under, however we would like to be saved under a different folder to eliminate the possibility of DWGs not being moved to the correct location. At the moment the macro also prints the drawing and then closes it. However it doesn't save the drawing before it closes it. It only saves the DWG causing any unsaved work in the drawing to be erased. We are looking to include both of these features. I do have some programming experience but not with VBA or macros. The current filepath for saving the DWG is X:\JOBS\18245\BUILD_DWGS\$ SW-FILES where the job number is the string of numbers. We would like it to be saved to X:\JOBS\18245\BUILD_DWGS\DWG'S\LASER. If anyone could help us update our macro or give some tips it would be much appreciated.

        • Re: Macro to save a dwg to a different folder.
          Deepak Gupta

          Try this macro. Basically you need to move one directory up and add path for additional folders.


          The macro has many variables which are not defined. You can also checks to make sure this is used on drawings and similar other things.

          • Re: Macro to save a dwg to a different folder.
            Christian Chu

            You needs windows API call for browser a folder:


            1) create a new module and add this code

            Option Explicit



            Public Type BROWSEINFO
                hOwner As LongPtr
                pidlRoot As LongPtr
                pszDisplayName As String
                lpszTitle As String
                ulFlags As LongPtr
                lpfn As LongPtr
                lParam As LongPtr
                iImage As LongPtr
            End Type
            Public Const BIF_RETURNONLYFSDIRS = &H1
            Public Const BIF_DONTGOBELOWDOMAIN = &H2
            Public Const BIF_STATUSTEXT = &H4
            Public Const BIF_RETURNFSANCESTORS = &H8
            Public Const BIF_BROWSEFORCOMPUTER = &H1000
            Public Const BIF_BROWSEFORPRINTER = &H2000
            Public Const BIF_NEWDIALOGSTYLE = &H40
            Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LongPtr, ByVal pszPath As String) As LongPtr
            Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr
            Public Function GetFolder(ByVal sTitle As String) As String
                Dim bInf As BROWSEINFO
                Dim retval As LongPtr
                Dim PathID As LongPtr
                Dim RetPath As String
                Dim Offset As Integer
                bInf.lpszTitle = sTitle
                bInf.ulFlags = BIF_NEWDIALOGSTYLE
                PathID = SHBrowseForFolder(bInf)
                RetPath = Space$(512)
                retval = SHGetPathFromIDList(ByVal PathID, ByVal RetPath)
                If retval Then
                    Offset = InStr(RetPath, Chr$(0))
                    GetFolder = Left$(RetPath, Offset - 1)
                End If
            End Function



            Then you can call it anywhere you want: