Link to home
Start Free TrialLog in
Avatar of dougc
dougc

asked on

Code example of V5 and Word 97 Integration

I need a source code example of the following:

From VB5 I want to callup Word 97 and create a new document and/or edit an existing document. I am storing the document in a data base file so I want to pass the document to Word using the VB5 program. When the user clicks on save in Word I want to have Word send the document to the VB5 program. In other words I need to override the Word 97 FileSave function.

Lastly, I want to do all the programming in VB5 not (VBA within Word 97) and not by using Macros.
Avatar of chdy
chdy

Option Explicit
Dim PicFile, SaveFile As String
Dim WordBasic As Object
Const OLEAutoWord As String = "word.basic"

Private Sub cmdPic_Click()

dlgOPen.DialogTitle = "Picture Load"
dlgOPen.Filter = "bmp Picture(*.bmp)|*.bmp"
dlgOPen.Action = 1

PicFile = dlgOPen.filename
imgPic.Picture = LoadPicture(PicFile)

End Sub

Private Sub cmdWord_Click()

dlgOPen.DialogTitle = "Document Save"
dlgOPen.Filter = "Document Save(*.doc)|*.doc"
dlgOPen.Action = 2

SaveFile = dlgOPen.filename

If SaveFile = "" Then
  Exit Sub
End If

Set WordBasic = CreateObject(OLEAutoWord)

'word execution display

If chkWord.Value = 1 Then
   WordBasic.Appshow
End If

  With WordBasic
       .filenewdefault
       .startofdocument
       .Bold
       .Underline
       .Insert "Sample"
       .Insert vbCrLf
       .insertpicture PicFile
       .Insert vbCrLf
       .Insert Text1.Text
       .filesaveas SaveFile
  End With
 
  Set WordBasic = Nothing
 
End Sub

'This  is sample program.
   Good Luck
Avatar of dougc

ASKER

Thank you for your answer chdy but we are looking to open Word with a document we provide, let Word take over for a while while the document is edited and then when we click "Save" in word, somehow communicate that to our VB application and allow our application to handle the saving process. When we tried your code example it worked good except once word was started it seemed to be detached from our VB app. We had no control of what Word was doing at the point when we were ready to save the document.
ASKER CERTIFIED SOLUTION
Avatar of Dalin
Dalin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bought This Question.
I did not understand what you mean, Mirkwood. Could you explain a little ?