Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 09-10-2018, 04:17 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 appear to have some confusion with your syntax, and while I can't test it without access to the two documents the following should be a deal closer to what you require


Code:
Private Sub CommandButton1_Click()
Dim DocSrc As Document, DocTgt As Document
Dim RngSrc As Range, 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("Demo").Range
        Set RngTgt = DocTgt.Bookmarks("spec").Range
        RngTgt.FormattedText = RngSrc.FormattedText
        RngTgt.Bookmarks.Add "spec"
    End If

    If CheckBox2.Value = True Then
        Set RngSrc = DocSrc.Bookmarks("Surveys").Range
        Set RngTgt = DocTgt.Bookmarks("surveys").Range
        RngTgt.FormattedText = RngSrc.FormattedText
        RngTgt.Bookmarks.Add "surveys"
    End If

    DocTgt.Range.Fields.Update
    Application.ScreenUpdating = True
    Set DocSrc = Nothing
    Set DocTgt = Nothing
    Set RngSrc = Nothing
    Set RngTgt = Nothing
End Sub
Thank you so much! This has helped a little bit. The document is now opening, however it's not copy and pasting the bookmarked sections from the other document to the activedocument, as it doesn't seem that there is anything in the code about copy and paste. Would it be better if I was pulling the data from an excel spreadsheet instead of a doc? Also, just for learning purposes, can you explain to me about the formatted text code, and the end code where you're setting them to Nothing? Your help is greatly appreciated!
Reply With Quote
 

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:26 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