So with this 3rd party software, it definitly has to be bookmarks? I have tried, but I really don't think it can repeat the bookmark. There might be another way, but I can't think of anything. I was going to suggest using mail merge but it sounds like you already know that won't work. Anyone else????
normally you would solve this using REF fields. But I don't now if they are provided in your 3rd party interface.
But anyway: if the bookmark is [INSPECTOR] is placed in your document you can insert a REF field linked to this bookmark. (Insert - Field - REF). When you check the Fieldcodes box in Tools - Options this field would look like this: { REF INSPECTOR }
Thanks. The REF field appears to be a great solution. Here's what I did --
*** Enabling field codes.
Click Tools,
Click Options,
Click View tab,
Click Field codes (in the Show section),
[Optional] Click Always (in the Field shading drop down).
*** Inserting REF BOOKMARK.
Position cursor to desired insertion point.
Click Insert,
Click Field,
Click Links and References (from the Categories box),
Click Ref (from the Field names box),
Type the name of the bookmark in the Field codes input box.
(To be on the safe side, I made sure that I was inserting a predefined bookmark.)
I've tried using the REF BOOKMARK approach but I can't get the VBA code to insert the data at the second instance of the bookmark. Any tips or sample code to help with this problem?
Thanks for the Find/Replace method (which definitely works). It's unusual that there isn't a simpler solution for a circumstance that I am sure people encounter all the time (needing to populate multiple instances of a bookmark with the same data). Thanks again!
I can't seem to get the Find/REplace method to work for multiple fields. Here is the code I was using for the REF MERGEFIELD attempt. Any suggestions as to why it is not inserting the text in the second instance of the bookmark?
Private Sub cmdOK_Click()
Application.ScreenUpdating = False
With ActiveDocument
.Bookmarks("Recipient".Range.Text=
txtRecipient.Value
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Create a property called Inspector in File|Properties and Custom tab.
Now whereever you need this value in the document put a field {DOCPROPERTY "Inspector"}.
Use the old Ctrl-A, F9 trick to refresh fields whenever you change the value of Inspector under File|Properties and hey presto!
I use this technique all the time. It works, it's simple and it saves time. Only problem is that most people using my templates type over the field instead of changing the property but I haven't found a solution to that.
plantj has a good idea with using DocProperty. A possible solution to his problem with users typing over the field is to embed the field code in a form field. That way the Ctrl-A-F9 will always revert the form field to its original value, that is, the value of the field code inside it. Users can type whatever they want into the form field, it will look differently, but a refresh will bring back your value. Of course if they deliberately edit the form field itself....you could always do continous section breaks, locking the forms etc. etc.
The following will insert a form field, with the DocProperty value, anywhere you want, as many times as you want.
Sub MakeFieldInForm()
' make a form field and insert a field code
'
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With Selection.FormFields(1)
.Name = "Text1" ' or whatever you like
.Enabled = False
With .TextInput
' insert a field code into text value of form field
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="DocProperty""MyField"""
' MyField could be a string variable
' selected from a user form listing all
' of your custom docproperties
End With
End With
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.