P
peter.thompson
I am trying to insert some excel data into a word doc & have never done
this before (and still a newbie at VBA). In order to get started I
have been playing at getting the basics right.
Have set up bookmarks in the Word doc ("test") called "customer" and
"solution". I have set up a commandbutton on the worksheet to open the
word document. When the commandbutton is activated, apart from opening
the word document, I want the document to automatically insert text
into the word doc.
Have used the following code:
Sub Commandbutton6_Click()
Dim wdApp As Word.Application
Dim wdDoc As Document
Dim wdRng As Word.Range
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\test")
wdApp.Visible = True
Dim myArray()
Dim wdBkmk As String
myArray = Array("customer", "solution")
SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(0)).Range
wdRng.InsertBefore ("test")
SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range
wdRng.InsertBefore ("test again")
SetwdApp = Nothing
SetwdRng = Nothing
End Sub
The document opens ok, but keep getting an error:
"Runtime 91 error - Object variable or With block variable no set"
Tried many things without success -any help on this to get me started
with the basics would be most appreciated.
Cheers
Peter
this before (and still a newbie at VBA). In order to get started I
have been playing at getting the basics right.
Have set up bookmarks in the Word doc ("test") called "customer" and
"solution". I have set up a commandbutton on the worksheet to open the
word document. When the commandbutton is activated, apart from opening
the word document, I want the document to automatically insert text
into the word doc.
Have used the following code:
Sub Commandbutton6_Click()
Dim wdApp As Word.Application
Dim wdDoc As Document
Dim wdRng As Word.Range
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\test")
wdApp.Visible = True
Dim myArray()
Dim wdBkmk As String
myArray = Array("customer", "solution")
SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(0)).Range
wdRng.InsertBefore ("test")
SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range
wdRng.InsertBefore ("test again")
SetwdApp = Nothing
SetwdRng = Nothing
End Sub
The document opens ok, but keep getting an error:
"Runtime 91 error - Object variable or With block variable no set"
Tried many things without success -any help on this to get me started
with the basics would be most appreciated.
Cheers
Peter