-
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
-
Do we take it that the macro is in the document 'Master Documents File.docm'? That being the case
Code:
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
-
That did it - Thanks Graham!:yes