Word 97 and Visual Basic 4.0 16 bit

I am using Visual Basic 4.0, 16 bit, and have Word97 installed on the same machine. I'm able to open Word and insert a metafile, while the Visual Basic program is running, without any problems.
If I try to programmatically open Word and insert the same metafile, Word crashes with an Invalid Page Fault. I only have 32M of RAM on this machine. Am I asking too much from the hardware, or is there something different about vb 4.0 16 bit code? Is there something about the OLE I need to change? I noticed that on a machine with both VB4.0 16 bit, and VB 6.0 installed, it works (running 4.0) I will attach the small code segment...

Set NewDoc = CreateObject("word.application")
NewDoc.Documents.Add
NewDoc.Visible = True

With NewDoc.selection
    .inlineshapes.addpicture filename:="C:\hpgraph.wmf", linktofile:=False, savewithdocument:=True
   
jscharpfAsked:
Who is Participating?
 
pclementConnect With a Mentor Commented:
ischarpf:

Declare it as Object first and then use CreateObject to create the instance:

Dim NewDoc as Object

Set NewDoc = CreateObject("Word.Application")

Like I said, I'm not sure if this will work, but give it a try and see if it makes any difference.

 
0
 
jscharpfAuthor Commented:
I forgot.

It opens word ok, but crashes at the line that inserts the picture.

Jeff
0
 
pclementCommented:

Somewhat perplexing. Are you using early or late binding on the Word object?

In other words if you are declaring NewDoc as Word.Application, try using late binding and declaring NewDoc as Object.

This is just a stab in the dark, but early binding sometimes fails between 16 and 32-bit COM objects.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
jscharpfAuthor Commented:
pclement
Thanks for the response.

I declared NewDoc as Object (globaly) in the declarations section.
Was I to do this before or after declaring newdoc as word.app?

Jeff
0
 
georgemanCommented:
jscharpf
I tested your source code on my PC and it works fine in environment: VB4 16-bit, Word 97.
I only added:
End With

I have no idea why it crashed on you PC.
Did you try use Word.Basic instead Word.Application ?

Regards
George
0
 
jscharpfAuthor Commented:
Thanks,
I re-installed everything, but only installed VB4.0 16 bit. It seems to work ok.

Jeff
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.