Results 1 to 12 of 12

Thread: Copy Bookmarked Text and 'Paste' into Bookmarks in New Document

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    Thanks so much, Greg.

    I have managed to get your second example to work with the first so it now just takes the text without the return character.

    I have one final question - In some scenarios one or more of my bookmarks from the Source Document might be deleted by the user (e.g. where that section was not relevant for their requirements) is there a way to state that if one of the bookmarks referred to in the code can't be found / doesn't exist then to move onto the next rather than crashing/stopping the macro?

      Sub ScratchMacro()
         'A basic Word macro coded by Greg Maxey
        Dim oTarDoc As Document, oSourceDoc As Document
        Dim oRng As Word.Range
        Dim oRngSource As Word.Range
        Set oSourceDoc = ActiveDocument
        Set oTarDoc = Documents.Open("C:\Users\herriale\Desktop\New folder\Phase 2\Template (MY.G.PBR) 31.3.15.dotm")
        With oTarDoc
        'box 1
            Set oRng = .Bookmarks("PlayerName").Range
            Set oRngSource = oSourceDoc.Bookmarks("wholename").Range
            oRngSource.End = oRngSource.End - 1
            oRng.Text = oRngSource.Text
            .Bookmarks.Add "wholename", oRng
        'box 2
            Set oRng = .Bookmarks("Club").Range
            Set oRngSource = oSourceDoc.Bookmarks("wholeclub").Range
            oRngSource.End = oRngSource.End - 1
            oRng.Text = oRngSource.Text
            .Bookmarks.Add "wholeclub", oRng
            End With
    lbl_Exit:
        Exit Sub
    End Sub
    Last edited by Aussiebear; 09-04-2024 at 11:07 PM.

Tags for this Thread

Posting Permissions

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