#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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. |
#4
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
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 |
#6
|
||||
|
||||
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] |
#7
|
|||
|
|||
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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
split word document based on bookmarks with each new document title of the bookmark | megatronixs | Word VBA | 9 | 09-05-2020 02:29 PM |
How to have the location (path) of the Word document on the title bar? | Jamal NUMAN | Word | 24 | 09-06-2017 12:18 PM |
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 Text to count words WITHOUT title page | ingmar.s | Word | 3 | 10-08-2009 10:23 AM |