Solved

Code example of V5 and Word 97 Integration

Posted on 1998-04-26
5
224 Views
Last Modified: 2010-08-05
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.
0
Comment
Question by:dougc
5 Comments
 
LVL 1

Expert Comment

by:chdy
ID: 1429892
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
0
 

Author Comment

by:dougc
ID: 1429893
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.
0
 
LVL 9

Accepted Solution

by:
Dalin earned 400 total points
ID: 1429894
douge,
Try to use an OLE control in your VB form, bound to a data control, with the database field being a OLE MSWord Document.
You can set the size of the OLE container. When you need to edit the word document, just click on the OLE, when you finish, you just neeed to click elsewhere in the vb form. and the nice thing is, when you move your records, the word document field will give you the proper document.  
If you have questions or need further help, let me know.
Regards
Dalin
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1429895
Bought This Question.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1429896
I did not understand what you mean, Mirkwood. Could you explain a little ?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 75
Sending a email via excel using vba 6 96
How to produce a SHA-1 hash function in vb6 in order to save it to a table 8 51
Problem to line 23 53
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question