J
jsherk
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!
Code:
--------------------
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
--------------------
--
jsherk
------------------------------------------------------------------------
jsherk's Profile: http://www.thecodecage.com/forumz/member.php?u=2112
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207672
http://www.thecodecage.com/forumz
--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---
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!
Code:
--------------------
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
--------------------
--
jsherk
------------------------------------------------------------------------
jsherk's Profile: http://www.thecodecage.com/forumz/member.php?u=2112
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=207672
http://www.thecodecage.com/forumz
--- news://freenews.netfront.net/ - complaints: (e-mail address removed) ---