Thursday 6 September 2012

export all pages in visio 2010 to jpg

I was working on a diagram in visio that had 20 pages. I needed to export all of them to jpg but I didn't want to click file -> save as 20 times. I found a bit of code online and it just needed to be changed slightly for visio 2010.

In visio click View -> Macros. Type the name of the macro (I called mine saveallpages) and click the Create button. The code should look like this.

Public Sub saveallpages()

  Dim i As Integer

  Dim formatExtension As String

  formatExtension = ".jpg"

  

  '// Init folder, doc and counter:

  folder = ThisDocument.Path

  Set doc = Visio.ActiveDocument

  i = 1

  '// Loop through pages:

  For Each pg In doc.Pages

    '// Setup the filename:

     FileName = Format(i, "000") & " " & 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

End Sub

6 comments:

  1. Tx man, but doesn't work for me. In the debugger, the following line is highlighted:
    "Call pg.Export(folder & FileName)"


    Any idea what i should do to fix?
    Thanks again

    Ido

    ReplyDelete
  2. Hmm not sure it's just something that I needed at the time. My guess is that the folder variable comes from ThisDocument.Path. Maybe if you don't have a visio open or its on a network path it won't work.

    Try this:
    Copy the visio diagram to your desktop.
    Make sure to open the visio diagram from your desktop
    Now go to view -> marcros
    Type the name of the macro "saveallpages" and click the create button
    Delete what ever code is there by default
    Copy paste my code in
    Run it
    The jpgs will be created on your desktop (where the visio diagram that you have open is located)

    ReplyDelete
  3. This is so great. Can you help me customize this to save in a new folder on the desktop and save with only the filename on the tabs and not include the 001? I am not a code person but this may be the answer to all of my questions. Thanks,Denise

    ReplyDelete
  4. Thank you...If I haven't seen this blog, I could have gone through the tedious process in saving 100+ sheets :)

    ReplyDelete
  5. What a great help! cant believe the latest version still cant do this with out a macro, thanks for posting this.

    ReplyDelete
  6. Was looking everywhere for a solution to this and yours worked very well thanks! I tweaked it a bit to just say "Slide - " rather than the slide number. Thanks again as i had a huge number of slides to save and doing them one by one was not an option!

    ReplyDelete