Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2018, 11:26 AM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default Macro to auto-save pdf using text on page + current date

I have done a bit of research on this topic, but can't seem to find exactly what I am looking for. I would like to create a macro - preferably a keyboard shortcut over a button - that will allow me to automatically create a pdf copy of the document using a specific naming convention. This is the naming convention:



Boilerplate - Lorem Ipsum - Date

Where "Boilerplate" is the same text every time, regardless of the document; "Lorem Ipsum" is text found on the page, highlighted in red in the attachment; and "Date" is the current date in the "yyyy-mm-dd" format.

I'd prefer the pdf to save wherever the document is, but if that is a hassle to code, saving to the desktop would be fine.

Finally, I was just introduced to Word's field code display feature (thanks macropod!) and am wondering if it's possible to use that (or another feature) to create "linked text"; in other words, text that changes based on designated reference text. For example, in the attachment, I've highlighted two instances of "Lorem ipsum". I'm looking for a way to change the first instance that instantly changes the other instance in the table. I assume this can be accomplished using the bracketed ( {{}} ) field code display, but I'm not sure. This is important to the pdf macro, because it draws on this text to create the filename.

Let me know if you have any questions; thanks in advance!
Attached Images
File Type: png template example.PNG (38.8 KB, 20 views)
Reply With Quote
  #2  
Old 02-01-2018, 03:44 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There are numerous ways of replicating text. See: https://gregmaxey.com/word_tip_pages...ting_data.html
In this case, a mapped content control might work best, as a macro can then reference that for the save name.

The code for the saving isn't especially complicated, but we'd need to know what data replication method you've implemented before the code could be written.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-02-2018, 03:04 PM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

Great - let's go with content controls. I can follow what is needed up until the VBA code listed in the "Advanced Custom Mapping" section. Do I need to go that route, or can I just follow the simpler method explained above it?
Reply With Quote
  #4  
Old 02-02-2018, 04:10 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Rather than using the VBA code listed in the "Advanced Custom Mapping" section, you might want to read a little further on and go to the 'Content Control Tools' page and download the addin there.

A simpler alternative would be to use a ContentControlOnExit macro in the 'ThisDocument' code module of either the document or its template, coded along the lines of:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
If CCtrl.Title <> "Parent" Then Exit Sub
With CCtrl
  If .ShowingPlaceholderText = False Then
    ActiveDocument.SelectContentControlsByTitle("Child")(1).Range.Text = .Range.Text
  Else
    ActiveDocument.SelectContentControlsByTitle("Child")(1).Range.Text = "XXXX"
  End If
End With
End Sub
where 'Parent' is the title of the Content Control you type in and 'Child' is the title of the Content Control the typed string is to be replicated in.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-02-2018, 04:55 PM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

Sorry, I'm not sure I follow what you mean by "Parent" and "Child". But I was able to accomplish what I wanted using one of the predefined document types ("Company").

Is this enough information to construct the pdf macro, or do I need to implement the VBA code you provided first?
Reply With Quote
  #6  
Old 02-02-2018, 05:05 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by hysterical.useless View Post
Sorry, I'm not sure I follow what you mean by "Parent" and "Child".
As indicated in my previous reply, those are content control titles that you can add via Developer|Controls>Properties, after selecting the appropriate content control.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-02-2018, 05:32 PM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

I opened the property list. Each has a "(Name)" and "ThisDocument" attribute. The list is rather long, and I'm unsure if I need to be using to them.

I would assume the next step would be to create a macro for saving a pdf using the filename convention discussed in my original post. If we know I'm using the built-in "Company" control type for the "Lorem Ipsum" text in the filename, is there a way to grab that for the macro?
Reply With Quote
  #8  
Old 02-02-2018, 05:42 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by hysterical.useless View Post
I opened the property list. Each has a "(Name)" and "ThisDocument" attribute. The list is rather long, and I'm unsure if I need to be using to them.
What you're looking at has nothing to do with
Quote:
Originally Posted by macropod View Post
content control titles that you can add via Developer|Controls>Properties, after selecting the appropriate content control.
There are screenshots in the link I gave you, under 7. Content Controls - https://gregmaxey.com/word_tip_pages...ting_data.html
Quote:
Originally Posted by hysterical.useless View Post
If we know I'm using the built-in "Company" control type for the "Lorem Ipsum" text in the filename, is there a way to grab that for the macro?
That's not the issue. The issue is the content replication. In any event, it's unwise to repurpose a built-in content control the way you propose.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 02-02-2018, 05:52 PM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

Sorry if I'm not understanding - I am completely new to content controls - but what exactly is it that you need me to do at this point? I have my "Lorem ipsum" text replicating throughout the document as needed now. That solves the second part of my two-part issue in the original post, I think.

Now I just need to know how to write a pdf-save macro that saves the filename according to some boilerplate text at the front, my "Lorem ipsum" text currently being used with a content control, and the computer's internal date.

Am I missing something? Am I skipping a step? Apologies for all the questions.
Reply With Quote
  #10  
Old 02-02-2018, 05:53 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

So what are you typing the text that's to become part of the filename into, and how is the replication being done?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 02-05-2018, 11:49 AM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

Sorry for the delayed response. See attached image, viewed from Design Mode. I added those content controls around the "Lorem ipsum" text by going to Insert > Quick Parts > Document Property > Company. When I edit any instance of "Lorem ipsum" within these content control brackets, it changes all other instances on the page, which is exactly what I needed.
Attached Images
File Type: png content control visual.PNG (41.0 KB, 13 views)
Reply With Quote
  #12  
Old 02-05-2018, 12:59 PM
macropod's Avatar
macropod macropod is offline Macro to auto-save pdf using text on page + current date Windows 7 64bit Macro to auto-save pdf using text on page + current date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case, you could use a macro like:
Code:
Sub SaveAsPDF()
Dim StrName As String
With ActiveDocument
  StrName = "\Boilerplate - " & .BuiltInDocumentProperties("Company") & " - " & Format(Date, "YYYY-MM-DD")
  .SaveAs FileName:=.Path & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
End With
End Sub
which you could assign to a keyboard shortcut.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 02-05-2018, 02:17 PM
hysterical.useless hysterical.useless is offline Macro to auto-save pdf using text on page + current date Windows 10 Macro to auto-save pdf using text on page + current date Office 2016
Novice
Macro to auto-save pdf using text on page + current date
 
Join Date: Jan 2018
Posts: 12
hysterical.useless is on a distinguished road
Default

Works perfect! Thank you again for your help.
Reply With Quote
Reply

Tags
pdf export



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to auto-save pdf using text on page + current date Auto save macro brent chadwick Word VBA 10 10-25-2017 08:26 AM
How to save the current page in a new file with all the page settings (header, footer Jamal NUMAN Word 6 03-15-2012 03:27 PM
Macro to auto-save pdf using text on page + current date How to call current PC date and/or current PC year KIM SOLIS Excel 2 11-04-2011 06:09 PM
Macro to auto-save pdf using text on page + current date Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM
Macro to auto-save pdf using text on page + current date Auto insert current month's name and current year Styler001 Word 4 01-25-2010 06:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:02 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