Object doesn't support this property or method (Error 438)

G

gazza67

Hi,

I am using Word 2000 and Excel 2000. I want to run a script in an
excel document that will open a word document, go to a bookmark within
the document and then copy and paste some info from the word document
into the excel document (ie populate the worksheet from a word
document).

I have added a microsoft word reference to my excel script and the
script successfully opens the word document in question. However when
I get to the "Selection.GoTo What:=wdGoToBookmark" statement I get the
error Object doesn't support this property or method (Error 438).

Is anybody able to help me with this problem.

I will include the script code;

Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the
code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
' Set wrdDoc = wrdApp.Documents.Add ' create a new document
' or
Set wrdDoc = wrdApp.Documents.Open("G:\Gary\testing\handovertest
\Handovers\Aug\010807.doc")
' open an existing document
' example word operations
With wrdDoc
Selection.GoTo What:=wdGoToBookmark, Name:="aa"
End With
End Sub


Regards,

Gary
 
J

JE McGimpsey

Running in XL, the Selection object is the range or object selected in
XL, so it knows nothing about how to move in a Word document. Try
something like:

Public Sub GetInfoFromNewWordDoc()
Const sFILENAME As String = _
"G:\Gary\testing\handovertest\Handovers\Aug\010807.doc"
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim sText As String
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(sFILENAME)
With wrdDoc
sText = .Bookmarks("aa").Range.Text
End With
MsgBox sText
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top