![]() |
#10
|
||||
|
||||
![]()
Your use of terminology is confusing. It seems that you are inserting files into a document that have common bookmark names. Bookmark names must be unique so if you insert a second document with the same bookmarks as the first, something has to give. The only way to do this is to delete the bookmarks in the target document before inserting the next document.
It would be better to use content controls than bookmarks as these can have duplicated names, then loop through each content control with the same name and apply the values The following will loop through all the controls in the document body (for controls in other story ranges you will have to loop through those also): Code:
Dim OCC As ContentControl For Each OCC In ActiveDocument.ContentControls Select Case OCC.Title Case "Address" OCC.Range.Text = TextBox1.Text Case "Location" OCC.Range.Text = TextBox2.Text Case "HT_Type" OCC.Range.Text = TextBox3.Text Case "Time" OCC.Range.Text = TextBox4.value Case "Weather" OCC.Range.Text = TextBox5.Text Case "TestDate" OCC.Range.Text = TextBox6.value End Select Next OCC Set OCC = Nothing Or you could use the following macro to convert your bookmarks to controls (with the same proviso about story ranges - I may add this to the aforementioned add-in later) Code:
Sub ReplaceBookmarkWithCC() 'Graham Mayor - https://www.gmayor.com - Last updated - 20 Dec 2018 Dim oBM As Bookmark Dim oRng As Range Dim oCC As ContentControl Dim strTitle As String For Each oBM In ActiveDocument.Bookmarks strTitle = oBM.Name Set oRng = oBM.Range oBM.Delete Set oCC = oRng.ContentControls.Add(wdContentControlText) With oCC .Range.Text = oRng.Text .Tag = strTitle .Title = .Tag .MultiLine = True .SetPlaceholderText , , "Click or tap here to enter text." .LockContentControl = True End With Next oBM MsgBox "Replacements complete" lbl_Exit: Set oCC = Nothing Set oRng = Nothing Set oBM = 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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Cosmo | Word | 7 | 08-24-2018 01:46 PM |
![]() |
rdross51 | Word VBA | 2 | 06-01-2016 07:05 PM |
Find Bookmark, move to bookmark, execute code, repeat | raymm3852 | Word VBA | 10 | 04-15-2016 06:21 PM |
![]() |
highrise955 | Word VBA | 4 | 03-06-2016 04:48 PM |
![]() |
KateAus | Word VBA | 4 | 09-09-2012 08:40 PM |