lsivak
02-03-2016, 03:24 PM
Can someone please help with this? I have spent hours trying to get this to work, and have run into many errors.
The latest error, runtime error 91 of which is on the line .visible = True. What Am I doing wrong????
Sub WordBookmarks()
Dim strDoc As String
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wb As Workbook
Dim ws As Worksheet
Dim xlRange As Excel.Range
Dim Bookmark_1 As Excel.Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet2")
Set xlRange = Range("Bookmark_1")
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set wdApp = New Word.Application
Set myDoc = wdApp.Documents.Open("C:\Users\dnykg\Documents\Custom Office Templates\Agent Invoice - Bookmarks.dotm")
s = "Text to put after bookmark"
With myDoc.Bookmarks
.Item(Bookmark_1).Range.InsertAfter s
End With
myDoc.Save
myDoc.Close
Set wdApp = Nothing
Set myDoc = Nothing
End Sub
The latest error, runtime error 91 of which is on the line .visible = True. What Am I doing wrong????
Sub WordBookmarks()
Dim strDoc As String
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim wb As Workbook
Dim ws As Worksheet
Dim xlRange As Excel.Range
Dim Bookmark_1 As Excel.Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet2")
Set xlRange = Range("Bookmark_1")
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set wdApp = New Word.Application
Set myDoc = wdApp.Documents.Open("C:\Users\dnykg\Documents\Custom Office Templates\Agent Invoice - Bookmarks.dotm")
s = "Text to put after bookmark"
With myDoc.Bookmarks
.Item(Bookmark_1).Range.InsertAfter s
End With
myDoc.Save
myDoc.Close
Set wdApp = Nothing
Set myDoc = Nothing
End Sub