Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2018, 12:15 AM
gmayor's Avatar
gmayor gmayor is offline Auto-populating a document pulling data from external doc using a Userform with Checkboxes Windows 10 Auto-populating a document pulling data from external doc using a Userform with Checkboxes Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

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.
Attached Files
File Type: docx 2019 Master Specification - GM.docx (26.2 KB, 22 views)
File Type: docm Bookmarks.docm (25.6 KB, 29 views)
__________________
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
  #2  
Old 10-10-2018, 05:56 PM
kateabode kateabode is offline Auto-populating a document pulling data from external doc using a Userform with Checkboxes Windows 7 64bit Auto-populating a document pulling data from external doc using a Userform with Checkboxes Office 2016
Novice
Auto-populating a document pulling data from external doc using a Userform with Checkboxes
 
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
Reply

Tags
vba, word-vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform with Multiple Cascading Drop Down Lists Populated with External Source Data venganewt Word VBA 21 05-16-2018 02:05 PM
Auto Populating Data with Drop Down Menu vmangano Excel 4 12-20-2016 09:03 AM
Auto-populating a document pulling data from external doc using a Userform with Checkboxes UserForm Dropdown List Not Populating highrise955 Word VBA 14 04-10-2016 12:10 PM
Lack of email addresses auto-populating LarryK Outlook 0 10-10-2012 08:09 AM
Auto-populating a document pulling data from external doc using a Userform with Checkboxes "Auto-populating" data-worksheet to worksheet. meggenm Excel 4 02-04-2012 02:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft