So I recently was searching for a efficient way to export all pages as a DWG. I started with the excellent code from Visio Guy. I then adapted the code by editing the Macro of the Visio file to a .dwg extension , to export for AutoCAD and adapted the file format naming. Anyway I wanted to share this code adaption back to the community. We used a macro hotkey to really simplify the whole process incredibly for the team and so far it’s working a treat.
Public Sub ExportAllPages_ToDWG() Dim formatExtension As String formatExtension = “.dwg” ‘…or .bmp, .jpg, .png, .tif ‘// Init folder, doc and counter: Dim filename As String, folder As String folder = ThisDocument.Path Dim doc As Visio.Document Set doc = Visio.ActiveDocument Dim i As Integer i = 1 ‘// Loop through pages: For Each pg In doc.Pages ‘// Setup the filename: filename = ” x” & pg.Name ‘// Append ‘(bkgnd)’ to background pages: If (pg.Background) Then filename = filename & ” (bkgnd)” ‘// Add the extension: filename = filename & formatExtension ‘// Save it: Call pg.Export(folder & filename) i = i + 1 Next Cleanup: Set doc = Nothing End Sub