Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2021, 08:42 PM
Grinhook Grinhook is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Novice
Bookmarks vs Fields
 
Join Date: Aug 2021
Posts: 4
Grinhook is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 08-26-2021, 09:15 PM
gmayor's Avatar
gmayor gmayor is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 08-26-2021, 10:52 PM
Grinhook Grinhook is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Novice
Bookmarks vs Fields
 
Join Date: Aug 2021
Posts: 4
Grinhook is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old 08-27-2021, 01:38 AM
gmayor's Avatar
gmayor gmayor is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You may find https://www.gmayor.com/insert_content_control_addin.htm useful
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 08-27-2021, 05:32 AM
Grinhook Grinhook is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Novice
Bookmarks vs Fields
 
Join Date: Aug 2021
Posts: 4
Grinhook is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Thank you for sending this through. Have spent the last couple of hours reading and experimenting with controls. My only question relates to repetition within the document. If I have information in my header that is repeated (eg a proposal number), should I still use content controls and iterate through each of them to update, or is this scenario a better use of fields?

TIA - and enjoying learning something completely new about Word.
Reply With Quote
  #6  
Old 08-27-2021, 04:38 PM
Guessed's Avatar
Guessed Guessed is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

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
Reply With Quote
  #7  
Old 08-27-2021, 08:32 PM
gmayor's Avatar
gmayor gmayor is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
Originally Posted by Grinhook View Post
If I have information in my header that is repeated (eg a proposal number), should I still use content controls and iterate through each of them to update, or is this scenario a better use of fields?
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
Reply With Quote
  #8  
Old 08-29-2021, 03:23 AM
Grinhook Grinhook is offline Bookmarks vs Fields Windows 10 Bookmarks vs Fields Office 2019
Novice
Bookmarks vs Fields
 
Join Date: Aug 2021
Posts: 4
Grinhook is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bookmarks vs Fields Deleting only all bookmarks contents not the bookmarks adilprodigy Word VBA 1 10-11-2017 01:31 PM
Bookmarks vs Fields Form fields and bookmarks restrictions AttiCuS Word VBA 11 04-19-2016 02:40 AM
Bookmarks vs Fields Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM
Bookmarks vs Fields 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

Other Forums: Access Forums

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