open word file failes

A

anne

Hi,

I work under Windows 2000 with Word 2000 and try to open a
Word document out of an project application (version 2002).
The following code does not work:
Private Sub cb_Vorgaenge_Click()
Dim word As Object
Dim DocumentToOpen As String
Dim oDoc As Application

DocumentToOpen = "G:\dummy\Projektvorgänge.doc"
Set word = CreateObject("Word.Application")
Set oDoc = word.documents.Open(DocumentToOpen)
word.Visible = True
End Sub

If I try to open the document I get the message "types are
incompatible" and in the debug modus the value of oDoc is
nothing.
Can anybody help?
Thanks!
Anne
 
J

Jezebel

It might be that you are confusing VB by using 'Word' as a variable name,
since that's also the name of the object type. Type using oWord or some
such.



Hi,

I work under Windows 2000 with Word 2000 and try to open a
Word document out of an project application (version 2002).
The following code does not work:
Private Sub cb_Vorgaenge_Click()
Dim word As Object
Dim DocumentToOpen As String
Dim oDoc As Application

DocumentToOpen = "G:\dummy\Projektvorgänge.doc"
Set word = CreateObject("Word.Application")
Set oDoc = word.documents.Open(DocumentToOpen)
word.Visible = True
End Sub

If I try to open the document I get the message "types are
incompatible" and in the debug modus the value of oDoc is
nothing.
Can anybody help?
Thanks!
Anne
 
H

Helmut Weber

Hi Anne,
try this (VB 6.0):
It is assumed, that no copy of word is running.
Dim WordEdit As Object
Set WordEdit = CreateObject("word.application")
WordEdit.Visible = True
WordEdit.Documents.Open FileName:="c:\test\test.doc"
I don't think, you need anything more.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
J

Jezebel

Just spotted it:

Dim oDoc As Application

is wrong. oDoc is either an object (if you're using late binding) or it's a
Word.Document (if you're using early binding. But don't mix the two methods

Either install the libraries and use early binding:

Dim oWord as Word.Application
Dim oDoc as Word.Document

Set oWord = new Word.Application


or DON'T install the libraries and use late binding:

Dim oWord as Object
Set oWor = CreateObject("Word.Application")





Hi Jezebel,

I changed the variable name 'word' to 'WordObj', but it
has no effect, the error message is the same. The
libraries are included, too, so I have no idea yet why it
does not work.
Anne
 

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