|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
MS PUB: Create multiple JPGs with containing custom text and custom file names
Hi,
I'm trying to create multiple JPG files with a birthday greeting for use on Facebook (Full explanation at end) Using MS Publisher. So each JPG would have a message saying "happy Birthday <<Name>>" and would save to a file named <<name>>.jpg I've created the start of an excel file with 3 columns: Name, Save folder path and file name which should be attached to this post hopefully, but this is as far as I can get using the merge feature (I have previously used Mail merge with Excel to create newsletter style personalised emails so I have a little experience but not much). My purpose behind this is I have several thousand Facebook friends, many with the same name and I like to put up birthday greeting every day, changing the background picture every year to keep it fresh. In previous years I have created a template with publisher and gone through the birthday names every morning, changing the name and saving each JPG separately. I figure I can use the file names from the previous year to populate the excel list fully and automate the process to give me a folder with 500+ JPGs all named after the greeting it contains (Aaron.jpg, Adam.jpg, Allen.jpg etc.) allowing me to just click on each birthday profile and add the picture without having to create new files each day as needed. Thanks in advance for any help or advice Tim |
#2
|
||||
|
||||
I don't know enough about Publisher mail merges to know if this is possible without coding so I would use a macro to output jpg files.
Code:
Sub TestExport() Dim sName As String, sPath As String With ActiveDocument.MailMerge.DataSource .ActiveRecord = 1 Do sName = .DataFields.Item("Name").Value sPath = .DataFields.Item("JpgFolderPath").Value & "\" & .DataFields.Item("JpgFileName").Value ActiveDocument.Pages(1).SaveAsPicture Filename:=sPath, pbResolution:=pbPictureResolutionWeb_96dpi If .ActiveRecord = .RecordCount Then Exit Do .ActiveRecord = .ActiveRecord + 1 Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thank you Andrew, I will try this tomorrow morning and let you know how it went.
(I also realised after I submitted this post that I had used the wrong forum. so I apologise if I made any admins make a frowny face). |
#4
|
|||
|
|||
Ok so I tried played about with this macro this morning and it is outputting to the correct location in the correct format (JPEG) with the correct file names, unfortunately the name field within the pictures all read "Name" though instead of the name from the spreadsheet and I can't see a way to fix that.
I have attached a JPG output and the publisher file in a compressed folder. Thanks for any further help Tim |
#5
|
||||
|
||||
Hmm, yes, I tested it on my machine and I got the same result as you even though the preview showed the right thing.
OK, try this instead. Get rid of the merge fields from the page and make sure the cursor is sitting in the text frame where you want the name to appear. (The text frame should be otherwise empty so use a different frame than the good wishes lines). Then try this version of the macro. Code:
Sub TestExport() Dim sName As String, sPath As String, aRng As TextRange Set aRng = Selection.TextRange With ActiveDocument.MailMerge.DataSource .ActiveRecord = 1 Do sName = .DataFields.Item("Name").Value aRng.Paragraphs(1).Text = sName sPath = .DataFields.Item("JpgFolderPath").Value & "\" & .DataFields.Item("JpgFileName").Value ActiveDocument.Pages(1).SaveAsPicture Filename:=sPath, pbResolution:=pbPictureResolutionWeb_96dpi If .ActiveRecord = .RecordCount Then Exit Do .ActiveRecord = .ActiveRecord + 1 Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
Firstly, thanks for your help with this Andrew.
I tried your 2nd macro and it correctly saves the first picture but then stops. Thanks for any further help Tim Last edited by Skyfawn; 07-31-2021 at 04:28 AM. |
#7
|
||||
|
||||
This Publisher code is annoying to debug. Try this one (again, after selecting the frame where the name should sit). It works for me and appears a bit more robust.
Code:
Sub TestExport() Dim sName As String, sPath As String, aRng As TextRange Set aRng = Selection.ShapeRange(1).TextFrame.TextRange With ActiveDocument.MailMerge.DataSource .ActiveRecord = 1 Do sName = .DataFields.Item("Name").Value aRng.Text = sName 'sPath = ActiveDocument.Path & "\" & .DataFields.Item("JpgFileName").Value sPath = .DataFields.Item("JpgFolderPath").Value & "\" & .DataFields.Item("JpgFileName").Value ActiveDocument.Pages(1).SaveAsPicture Filename:=sPath, pbResolution:=pbPictureResolutionWeb_96dpi If .ActiveRecord = .RecordCount Then Exit Do .ActiveRecord = .ActiveRecord + 1 Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
Thank you Andrew you just made it to the top of the list of my favourite people
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need to create an office (word) add-in to create a custom ribbon bar with icons | avogt | Word VBA | 1 | 05-18-2018 06:06 AM |
Custom table in custom Word 2010 template | Hans L | Word Tables | 5 | 04-17-2018 08:42 AM |
Create Custom Month | Cfwoodbury | Outlook | 0 | 02-11-2015 09:55 AM |
custom dictionary of full names? | srobbins | Word | 3 | 06-17-2012 03:22 AM |
create footnotes from custom text | mosrozen | Word VBA | 2 | 06-14-2012 06:59 AM |