Consulting

Results 1 to 10 of 10

Thread: Macro to export all publisher pages as individual jpg or png

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Newbie
    Joined
    Apr 2016
    Posts
    1
    Location

    AWESOME! Totally worked.

    OMG, I am SOOOOO glad I found this (pretty old) thread!

    I had a 631-page Publisher file I needed to get into PowerPoint for a slideshow and was beginning to have a panic attack at the idea of save each page as a JPEG one at a time! But, this worked perfectly and you helped me out tremendously. Thank you for posting it!

    Quote Originally Posted by jsherk View Post
    There is not much info out there on VBA programming for Publisher (I had a hard time finding it anyway), and I needed to export each page in a publisher file as an individual graphic (jpg or png). Although you can do a Save As and save each page one at a time, that becomes a little tedious, so I wrote this macro to export all the pages individually as a graphics file.

    Hope this is helpful to somebody!

    Sub Export_All_Pages_As_Graphic()
    'Ask whether to proceed or not
    BtnPress = MsgBox("Save all pages as individual pictures?", vbOKCancel)
    'If they pressed OK then proceed, otherwise do nothing.
    If BtnPress = 1 Then
    'Make sure two-page spread is set to FALSE, otherwise it might export the two pages as one picture, instead of individually.
    'NOTE: This may not be necessary, but just in case!
       ActiveDocument.ViewTwoPageSpread = False
       'How many total pages in document?
       TotalPages = ActiveDocument.Pages.Count
       'Loop thru all pages one at a time
       For PgCnt = 1 To TotalPages
          'When you convert integer to string it adds a space in front, so need to remove the leading space
          PgNumber = Str(PgCnt)
          PgLen = Len(PgNumber)
          PgNumber = Right(PgNumber, PgLen - 1)
          'All names are three characters with leading zeros like 002.png 014.png 123.png
          If PgCnt < 10 Then
             PgFilename = "00" + PgNumber
             ElseIf PgCnt < 100 Then
             PgFilename = "0" + PgNumber
             Else
             PgFilename = PgNumber
          End If
          'Add the appropriate fileformat extension. You can use .png and .jpg for sure. There may be others, but did not test any.
          PgFilename = PgFilename + ".png"
          'Save the page
          ActiveDocument.Pages(PgCnt).SaveAsPicture (PgFilename)
       Next PgCnt
       'Tell them you are done and how many pages were saved
       MsgBox "DONE! Saved" + Str(TotalPages) + " pages."
    End If
    End Sub
    Last edited by Aussiebear; 04-09-2023 at 04:34 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •