Solved

Code example of V5 and Word 97 Integration

Posted on 1998-04-26
5
223 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 86
Macro which automatically sends attachment to Outlook 14 71
Macro: print each sheet to pdf using ExportAsFixedFormat 11 48
using web browser with BING 40 122
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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