#1
|
|||
|
|||
Bookmarks vs Fields
Hi all,
Getting back into VBA and this time working on Word (previous experience was in Access). At present I am preparing templates for proposal documentation. Our proposals contain a standard set of information (proposal number, title, client etc) and I immediately thought of using either supplied or custom document property fields. Doing some reading to get back up to speed and I have seen reference to either using fields or bookmarks to save document specific text. Strong suspicion that the the two approaches (fields/bookmarks) are intended to achieve different outcomes so would welcome guidance on which the best method to use. Intent is to capture document details in a UserForm and then populate throughout document. Cheers and TIA. |
#2
|
||||
|
||||
The optimum approach is to use content controls to accept the data as they are much more robust than bookmarks. For a text content control the following can be used to write a value from your userform to the appropriate control. Where there is no datato write to a control set the strValue to ChrW(8203) i.e. a zero length space.
Code:
Public Sub FillCC(strCCTitle As String, strValue As String) Dim CCtoFillRng As Range Set CCtoFillRng = ActiveDocument.SelectContentControlsByTitle(strCCTitle).Item(1).Range CCtoFillRng.Text = strValue lbl_Exit: Set CCtoFillRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
TY for the response. Reading into these now - protection for that part of the document does seem robust and will definitely help my achieve the aims.
Thanks again! |
#4
|
||||
|
||||
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Quote:
TIA - and enjoying learning something completely new about Word. |
#6
|
||||
|
||||
If the CCs are mapped to the same xml node then you can change one of the CCs to change them all. Alternatively, you can modify the code to replace the text in every instance of the CC with that title
Code:
Public Sub FillCC(strCCTitle As String, strValue As String) Dim aCC as ContentControl For each aCC in ActiveDocument.SelectContentControlsByTitle(strCCTitle) aCC.Range.Text = strValue Next aCC lbl_Exit: Exit Sub End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
||||
|
||||
The add-in I suggested makes it easy to map controls. Check the map check box and insert the control. Copy and paste the control wherever you want a duplicate. Whatever you enter in one of them will be duplicated in the others,
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
|||
|
|||
Thanks all. Have spent the weekend playing with content controls and to be honest have had limited success so still much to learn for me.
Have read Gregory Maxey's site on repeating data and his significant info on content controls. I had some problems mapping controls to existing nodes in XMLCustomParts and inconsistency in update throughout the document. Content controls are definitely the way for me to go, but some more reading yet. Going to use DocVariables in the short term (data is really only repeated on front page and in headers) until I read more into both XML and get a better understanding of the content control. Thanks for all the pointers to date. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deleting only all bookmarks contents not the bookmarks | adilprodigy | Word VBA | 1 | 10-11-2017 01:31 PM |
Form fields and bookmarks restrictions | AttiCuS | Word VBA | 11 | 04-19-2016 02:40 AM |
Form updating Bookmarks - writes to the bookmarks multiple times | PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |
How To Find Bookmarks and/or custom fields Inside Building Blocks, Office 2010 | thpanos | Word | 3 | 02-17-2013 08:49 AM |
autopopulating REF fields + bookmarks | valz | Word | 10 | 09-01-2011 08:18 AM |