View Single Post
 
Old 10-10-2018, 05:56 PM
kateabode kateabode is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Sep 2018
Posts: 16
kateabode is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Provided the bookmarks exist in both the source and target documents and the source bookmark actually contains text, then the code you posted will work. Bookmark names are case sensitive.

To demonstrate that it works see the attached which does meet the criteria (though I have used an activex button to call the code rather than a userform).
Personally I would use more descriptive bookmark names and not use the same names in source and target, but I have run with what you posted.
bmSrcA and bmTgtA would have been my preference.
Thank you so much. You have helped immensely.
I have inserted the bookmarks into the document correctly now but I'm wondering what the code might be to delete the bookmark if not ticked in the userform?

I have tried the below to no avail.

If CheckBox1.Value = True Then
Set RngSrc = DocSrc.BookMarks("A").Range
Set RngTgt = DocTgt.BookMarks("A").Range
RngTgt.FormattedText = RngSrc.FormattedText
RngTgt.BookMarks.Add "A"
ElseIf CheckBox1.Value = False Then
ActiveDocument.BookMarks("A").Delete
End If

I also tried this.

If CheckBox1.Value = True Then
Set RngSrc = DocSrc.BookMarks("A").Range
Set RngTgt = DocTgt.BookMarks("A").Range
RngTgt.FormattedText = RngSrc.FormattedText
RngTgt.BookMarks.Add "A"
ElseIf CheckBox1.Value = False Then
DocTgt.BookMarks("A").Delete
End If

UPDATE. For some reason it's deleting the bookmark from the Source doc rather than Target doc and I can't seem to get it to work out.

Last edited by kateabode; 10-10-2018 at 08:18 PM.
Reply With Quote