Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2021, 07:06 AM
Skyfawn Skyfawn is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Novice
MS PUB: Create multiple JPGs with containing custom text and custom file names
 
Join Date: Jun 2018
Posts: 6
Skyfawn is on a distinguished road
Default 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
Attached Files
File Type: xlsx 0-Names.xlsx (10.2 KB, 8 views)
Reply With Quote
  #2  
Old 07-28-2021, 07:14 PM
Guessed's Avatar
Guessed Guessed is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 07-29-2021, 01:12 AM
Skyfawn Skyfawn is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Novice
MS PUB: Create multiple JPGs with containing custom text and custom file names
 
Join Date: Jun 2018
Posts: 6
Skyfawn is on a distinguished road
Default

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).
Reply With Quote
  #4  
Old 07-30-2021, 02:11 AM
Skyfawn Skyfawn is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Novice
MS PUB: Create multiple JPGs with containing custom text and custom file names
 
Join Date: Jun 2018
Posts: 6
Skyfawn is on a distinguished road
Default

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
Attached Images
File Type: jpg Susan.JPG (101.5 KB, 14 views)
Attached Files
File Type: zip 0-Next.zip (59.8 KB, 8 views)
Reply With Quote
  #5  
Old 07-30-2021, 05:40 AM
Guessed's Avatar
Guessed Guessed is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #6  
Old 07-30-2021, 01:30 PM
Skyfawn Skyfawn is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Novice
MS PUB: Create multiple JPGs with containing custom text and custom file names
 
Join Date: Jun 2018
Posts: 6
Skyfawn is on a distinguished road
Default

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.
Reply With Quote
  #7  
Old 08-01-2021, 11:59 PM
Guessed's Avatar
Guessed Guessed is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #8  
Old 08-02-2021, 02:45 AM
Skyfawn Skyfawn is offline MS PUB: Create multiple JPGs with containing custom text and custom file names Windows 10 MS PUB: Create multiple JPGs with containing custom text and custom file names Office 2016
Novice
MS PUB: Create multiple JPGs with containing custom text and custom file names
 
Join Date: Jun 2018
Posts: 6
Skyfawn is on a distinguished road
Default

Thank you Andrew you just made it to the top of the list of my favourite people
Reply With Quote
Reply

Thread Tools
Display Modes


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
MS PUB: Create multiple JPGs with containing custom text and custom file names custom dictionary of full names? srobbins Word 3 06-17-2012 03:22 AM
MS PUB: Create multiple JPGs with containing custom text and custom file names create footnotes from custom text mosrozen Word VBA 2 06-14-2012 06:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft