Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-03-2014, 05:05 PM
smndnm smndnm is offline creating a new TITLE property from text already within document Windows 7 64bit creating a new TITLE property from text already within document Office 2010 32bit
Novice
creating a new TITLE property from text already within document
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Question creating a new TITLE property from text already within document

Hello, I have zero effective experience of VBA, although i can find Alt-F11 and navigate and edit, I can read basic VBA, I know what strings are. But I cannot write code and I am asking for your time and effort to provide me with a solution, or a 75% so that I am forced to learn this arcane art.



Scenario: I have a master document which is populated with customer data. This data is linked to >10 templates. These templates are then opened by a user (as a .docx), updated (by virtue of the linking) and saved as pdfs to another network folder with all the relevant customer data. each pdf has a unique filename. All the parts of the filename are contained in the document, albeit scattered about in the first page. There are 4parts to the filename. docnumber doctype sitename personname.

What does the VBA code look like to concatenate the bookmarks relating to each string and use that new concatenated string to specify the new TITLE propoerty so as to create the default "save as" filename. Also making the default "Save" document type a pdf is also useful, although I think this code is covered elsewhere here. The end result of this would mean a significant improvement in workflow, which is, I suppose, what computers are here for... Regards from Queensland.

Last edited by smndnm; 07-03-2014 at 05:07 PM. Reason: clarification of title
Reply With Quote
  #2  
Old 07-03-2014, 11:21 PM
macropod's Avatar
macropod macropod is online now creating a new TITLE property from text already within document Windows 7 32bit creating a new TITLE property from text already within document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Please clarify what you mean by 'master document' and 'template'. In Word, these have specific meanings, but you don't appear to be using them that way.

In Word, a 'master document' is a kind of document used to link a group of related documents. They are further described here:
http://office.microsoft.com/en-us/wo...005234679.aspx
Word 'master documents' are also regarded as highly unstable and prone to catastrophic data loss. See: http://word.mvps.org/FAQs/General/Wh...ocsCorrupt.htm

In Word, a 'template' is a file from which documents are created. The most common one is 'Normal.dot(m)'. All Word documents are based on templates. For more details, see: http://office.microsoft.com/en-us/wo...010030754.aspx

You say
Quote:
There are 4parts to the filename. docnumber doctype sitename personname
and ask:
Quote:
What does the VBA code look like to concatenate the bookmarks relating to each string
Before we can proceed with any of that, we'd need to know whether the docnumber etc. are contained within the bookmarks or have been inserted after them. That's because merely locating a bookmark, then inserting something doesn't necessarily add the content to the bookmarked range. This is very common when the bookmark initially consists of nothing more than an insertion point within the document, regardless of whether the data are added manually or by code. And, if the data are inserted after the bookmark, we'd need to know how many words each item consists of.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-04-2014, 04:18 AM
smndnm smndnm is offline creating a new TITLE property from text already within document Windows 7 64bit creating a new TITLE property from text already within document Office 2010 32bit
Novice
creating a new TITLE property from text already within document
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

Thanks for replying so soon Paul.
I am incorrectly using the term "Master Document". I am using one document and subsequently linking about 30 pieces of text to another set of documents (>10) which are currently templates (.dotx) This currently works very well, However I am looking to make the "Saving" function a little more automated and elegant, leaving only the selection of the folder location as the user interaction.

Of the 4 pieces of text in each template that I want to use 3 of them are linked from the first doc; being docnumber (4digits), sitename (2-3 words), personname (2 words) these are the bookmarks that you are refering to; so to answer your questionas best I can: I believe the text is contained within the bookmarks. The doctype is a string of normal text in the document.

We currently have a naming convention being "docnumber doctype sitename personname.pdf". This is a entered manually for each document on "save". My thinking is; as the information is already in the document content and Word uses the Title property as the suggested file name on save, I might be able to assemble the four pieces of text, concatenate them and make that string the Title property. There would be no issue with concatenting the strings as a line in the document prior to the macro making the new Title property if it simplfies the macro.

Regards.
Reply With Quote
  #4  
Old 07-04-2014, 04:27 PM
macropod's Avatar
macropod macropod is online now creating a new TITLE property from text already within document Windows 7 32bit creating a new TITLE property from text already within document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

OK, Given that you say the components are contained within the bookmarks, the code to give a SaveAs prompt with those components for the name would be something along the lines of:
Code:
Sub Demo()
Dim StrNm As String
With ActiveDocument
StrNm = .Bookmarks("docnumber").Range.Text & _
  .Bookmarks("doctype ").Range.Text & _
  .Bookmarks("sitename").Range.Text & _
  .Bookmarks("personname").Range.Text
End With
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = StrNm
  .Show
End With
End Sub
Note that there's no error-checking for characters that aren't valid for a filename. A small amount extra code would be needed for that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-04-2014, 05:57 PM
smndnm smndnm is offline creating a new TITLE property from text already within document Windows 7 64bit creating a new TITLE property from text already within document Office 2010 32bit
Novice
creating a new TITLE property from text already within document
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

Thanks Paul, this is fantastic, I would bever have got here on my own before the wet seasons starts. Now have plenty of homework getting to grips with the hows and whys of your code.

Further on my project list are:
invoking the macro correctly when saving the document (opened from the template).
updating the Title property so it stays with the resultant pdf.
Saving to pdf by default.

But I'll start a new thread topic for these should I need to (that's pretty optimistic of me, but one never knows)

Many Thanks from Queensland
Reply With Quote
  #6  
Old 07-04-2014, 07:39 PM
macropod's Avatar
macropod macropod is online now creating a new TITLE property from text already within document Windows 7 32bit creating a new TITLE property from text already within document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

You can make a macro run automatically whenever a document is created, via a Document_New macro in the template's 'ThisDocument' module. I'm not sure how invoking a SaveAs process at that time would fit in with your workflow, though.

Regarding "updating the Title property so it stays with the resultant pdf", you can do that by inserting:
.BuiltInDocumentProperties("Title") = StrNm
before the first:
End With

To make the default save format 'PDF', simply insert:
.Format = wdFormatPDF
before:
.Show
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-04-2014, 08:27 PM
smndnm smndnm is offline creating a new TITLE property from text already within document Windows 7 64bit creating a new TITLE property from text already within document Office 2010 32bit
Novice
creating a new TITLE property from text already within document
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

Thanks for this, I got to exactly the same code examples in the last couple of hours. Although my structure is still somewhat haphazard (guessing where code goes). I've started a new thread "How to invoke the macro correctly in the workflow" which continues this project but asks different questions.

Cheers
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a new TITLE property from text already within document split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
creating a new TITLE property from text already within document How to have the location (path) of the Word document on the title bar? Jamal NUMAN Word 24 09-06-2017 12:18 PM
creating a new TITLE property from text already within document How to specify Document Title from the body of my Document SymphonyTomorrow Word 9 08-05-2013 05:31 PM
Display Full File Path Name of Document in Title bar MS-Word 2010 Carlos06x Word 1 10-12-2011 10:39 AM
creating a new TITLE property from text already within document Creating Text to count words WITHOUT title page ingmar.s Word 3 10-08-2009 10:23 AM

Other Forums: Access Forums

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