copying data from word to excel with vba

T

tomek milewski

Hello,
I'm trying to open and mainipulate word document from excel macro.
I've written smthg like this, and it doesn't work in excel :( :

Sub example()
Dim WordObj As Object
Dim doc As Object

Set WordObj = CreateObject("Word.Application")
Set doc = WordObj.Documents.Open("c:\example.doc")
WordObj.Visible = True

WordObj.Selection.HomeKey Unit:=wdStory 'this line doesnt work

doc.Saved = True
WordObj.Quit
End Sub

HomeKey, MoveRight etc. doesn't work. They work only with no arguments.
Please, tell me why it fails and, what is more important, how to fix
it.

I'm using office 2000
 
T

tomek milewski

I found out what is the problem.

Error is
Runtime error 4120
it means that wdStory is a bad parameter.
wdStory, just like wdLine and others are just like constant integer.
And they are defined only in word. In excel can be proper numbers used.
It means, instead of:
wdStory should be used 6
wdSection: 8
wdLine: 5
wdWord: 2
wdCharacter: 1

Values of these constants can be checked with this short macro (in
word):
Sub check()
msgbox "wdLine is " & wdLine
End Sub
 
Top