Batch export Visio to DWG

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.

CODE FOLLOWS

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s