Consulting

Results 1 to 3 of 3

Thread: Error 5174

  1. #1
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Smile Error 5174

    Hi -I am a first time poster

    I have a word document with many bookmarks. I created the macro below to simply go to a bookmark in my file and insert it to a new file. If I open the file and click on the macro right away, it works. But after that, it throws the error 5174. Any help is appreciated. I am not very practiced in exploring these things in word

    Private Sub CommandButton2_Click()
    Windows("Master Documents file").Activate
    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
    Selection.InsertFile FileName:="Master Documents file.docm", Range:= _
    "Charter", ConfirmConversions:=False, Link:=False, Attachment:=False
    Windows("Master Documents file").Activate


    End Sub

    Thanks for even reading and help would be sooooooooooo appreciated

  2. #2
    Do we take it that the macro is in the document 'Master Documents File.docm'? That being the case

    Private Sub CommandButton2_Click()
    Dim oDoc As Document, oSource As Document
    Dim oRng As Range
        Set oSource = ThisDocument
        Set oDoc = Documents.Add(Template:="Normal")
        Set oRng = oDoc.Range
        oRng.FormattedText = oSource.Bookmarks("Charter").Range.FormattedText
        oSource.Activate
        Set oDoc = Nothing
        Set oSource = Nothing
        Set oRng = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location
    That did it - Thanks Graham!

Posting Permissions

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