Reading from an open word doc to excel

  • Thread starter Thread starter sparkle_guy
  • Start date Start date
S

sparkle_guy

I would like to read data from an open word document into an excel spread
sheet. I think the way to access the document is to use the getobject
method. I don't want users to have to enter the path name I just want to
have the word document open and read from there.

According to the help files for GetObject([pathname] [, class]) If the
pathname argument is omitted, GetObject returns a currently active object of
the specified type. The class has the format appname.objecttype

I have tried set myobject = getobject(,"word.documents") but get an 429
error message "Activex component can't create object".

Can some one help me here do I have the right syntax? do I have the correct
class syntax( I have tried other guesses without success).

Thanks in advance

Paul
 
Sub test()

Dim oWd

Set oWd = GetObject(, "word.application")

If Not oWd Is Nothing Then
MsgBox oWd.activedocument
Else
MsgBox "Word is not running"
End If

End Sub

notes:
1. if there is >1 instance of word runnnig then there is no guarantee on
which instance will be returned by getobject, nor is there any way to
control this
2. need to add some code to check if there is an activedocument
3. If you know the path to the word file you might be better off using that
as the first parameter otherwise (1) may trip you up...

Tim
 

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

Back
Top