Results 1 to 6 of 6

Thread: Copy Text from Bookmark in SourceDoc to use as Document Variable in NewDoc

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2022
    Posts
    3
    Location

    Copy Text from Bookmark in SourceDoc to use as Document Variable in NewDoc

    Hi,<br><br>I would like to have a Source Document set up with various bookmarks with text inside the bookmarks.&nbsp; I would then like to have different Templates with DocVariable fields throughout.&nbsp; When I create a new document from the template, I would like to run a macro that will copy the text from a particular bookmark in the SourceDoc and set it as the value for a particular DocVariable in the NewDoc.<br><br>This is what I have come up with, but I cannot get it to work for me, any help would be much appreciated.

    Private Sub Document_New()
        Dim oSourceDoc As Document 
        Dim oRng As Range 
        Set oSourceDoc = Documents.Open("SourceDoc")
        oRng.Text = oSourceDoc.Bookmarks("bookmark").Range.Text
        Set oVars = ActiveDocument.Variables
        oVars("doc_variable").Value = oRng.text
        Set oVars = Nothing
    End Sub
    Last edited by Aussiebear; 03-24-2025 at 05:34 AM. Reason: Edit post layout

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •