Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2018, 09:51 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
You don't need to copy and paste when using ranges. You can simply write one range to the other. Basically it writes what is in one named bookmark to the other.

It sounds like the source document has nothing in the named bookmark because you are using two bookmarks to set the sources. Bookmark the whole of the text segment and don't use start and end bookmarks.

The use of an Excel source for the data is not necessary.
Thanks Greg! This has really helped.

So I have edited the code for the 60 bookmarks I have. I was encountering a runtime error 5941 saying that the bookmarks weren't in the activedocument so I added code into the Object New Document to add the bookmarks. Then when I try to run the code it adds the bookmarks, opens the userform and external doc all without any errors but doesn't copy anything to the activedocument.

This is a sample of the code - I've only included one bookmark as to include them all would be far too long.



HTML Code:
Private Sub CommandButton1_Click()
Dim DocSrc As Document
Dim DocTgt As Document
Dim RngSrc As Range
Dim RngTgt As Range
    Set DocTgt = ActiveDocument
    Set DocSrc = Documents.Open("C:\Users\reception.AIRDG\Documents\Custom Office Templates\2019 Master Specification - Kate.dotm")

    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"
    End If

 DocTgt.Range.Fields.Update
    Application.ScreenUpdating = True
    Set DocSrc = Nothing
    Set DocTgt = Nothing
    Set RngSrc = Nothing
    Set RngTgt = Nothing
End Sub
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 04:43 PM.


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