?
Solved

Automating Word 97 contained in VB6 application OLEControl

Posted on 2001-07-10
11
Medium Priority
?
163 Views
Last Modified: 2012-06-21
I'm currently developing a VB6 application that contains an Word 97 DOC in an OLE Control in the main form.

In fact, I need to change some data in the form fields of the contained document depending on the VB application forms result. And the doc's intended to be visible all time.

I've been trying to use de DDE and the GetObject methods as well, but I wasn't able to make that run OK.

Does anyone know how can I do that?
Does anyone have any idea?


Suggestions will be welcome and

Code examples will be well rewarded in points.

Thanks.
0
Comment
Question by:sidou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 

Expert Comment

by:marksynnott
ID: 6269963
Hi I've done this using standard VB and creating an instance of Word this work in 97 and 2k. The code for vb should be something like this

 sFilename = "\\fff-ggg\CLAIMS\blaablaa.dot"
  Set objWord = CreateObject("Word.Application")
  objWord.Visible = True
  objWord.Documents.Add(sFilename)
  Set objDoc = objWord.ActiveDocument
  Set MyWordDoc = objDoc
  objDoc.Activate
  Call myWordDoc.AutoFillFormField("ClaimNumber",ClaimNumber)

The parm in the quotes is the name of field in the doc and the other parm claimnumber contains the value etc

The field claimnumber should be defined in your document as a text form field - on properties put its name claimnumber into the boomark field properties.

Then in the doc put the AutoFillFormField code which is


' Author mark J Sinnott May 19999
'
' This VB code allows merging of bookmarks from calling VB program.
'
'
'
'
'
Public Sub AutoFillFormField(FFName As Variant, FFResult As Variant)

  Dim FFNameStr As String
  Dim FFResultStr As String
  Dim myWordDoc As Document
  Dim myFormFields As FormFields
  Dim mycurff As FormField
  Dim myFFCount As Integer
  Dim mmm As Integer
 
  Dim curFFName, H As String
  Dim Ndex
 
    FFNameStr = FFName
    FFResultStr = FFResult
   
    Set myWordDoc = ActiveDocument
    Set myFormFields = myWordDoc.FormFields
   
    myFFCount = myFormFields.Count
    For Ndex = 1 To myFFCount
   
      Set mycurff = myFormFields.Item(Ndex)
         'MsgBox "mycurFormField Name = " & mycurff.Name
      curFFName = mycurff.Name
     
      If curFFName = FFNameStr Then
          mycurff.Result = FFResultStr
         
  '        Exit For
      End If
     
    Next
   
    Set mycurff = Nothing
    Set myFormFields = Nothing
    Set myWordDoc = Nothing

End Sub



0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6270339
Hearing... But why use an ole control in a COM age?
0
 
LVL 1

Author Comment

by:sidou
ID: 6270440
sorry, richie. I didn't understand your comment. Do you have any suggentions I could possibly use?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6271187
Yes. If you automates an instance of Word throught COM, you don't need to break your head using OLE Control )by the way, with limited options).
If you don't use automation before, ask and i put some example code here.
Using automation is like do what Word does but by code from within VB application.
0
 
LVL 1

Author Comment

by:sidou
ID: 6271266
that's exactly what I want to do. I've been working hard on that but, unfortunely, I wasn't able to develop that.
How do I automate an instance of word trough COM?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6271295
Well, here is 7 pm and i must go home. Only for a start:

' In your project, set a reference to Microsoft Word 8 or 9 (it depends on version you have installed) object library

' on declarations section of your main form

Option Explicit

Dim WordApp As Word.Application
Dim WDoc As Word.Document
Private Sub Form_Load()
Set WordApp = New Word.Application
With WordApp
    .Visible = True
    ' this is a reference to a new word document
    ' You could open an existing one.
    Set WDoc = WordApp.Documents.Add
   
    WDoc.Activate
    WDoc.SaveAs "c:\myword.doc"
End With
Set WDoc = Nothing
WordApp.Quit
Set WordApp = Nothing
End Sub
0
 

Expert Comment

by:marksynnott
ID: 6272642
Sidou

My vb code on the comment creates an instance of work and does puts the data into the doc. No controls required etc..
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6272982
Ups, marksynnott is right!
0
 
LVL 1

Author Comment

by:sidou
ID: 6273806
marksynnott

Yes, I've been tryng to use your suggestion but that's not quite what I wanted to do. I want to edit the document in the OLE control, not in word... maybe I wasn't specific at start, sorry...

But I don't want to create a new Word Window.... I want to edit the doc contained in the ole control in the same ole control...

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7153024
Hi sidou,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

sidou, Please DO NOT accept this comment as an answer.

EXPERTS: *** will either suggestion do what sidou wants?  If so, post and I'll recommend to split points
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 7182461
This question will be placed in PAQ, and points refunded.

Regards,

ComTech
Community Support Administrator  
Experts-Exchange  
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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