Solved

How to call MsWord from vb6

Posted on 2006-11-17
6
269 Views
Last Modified: 2010-04-30
Hi Experts,

I'm making an app. in vb6, it generates a lot of text that I need to copy to a word file, I need to put the code in a command button, so on the click event, the word must open with all the information.

Also is it possible to name that file from the app and leave it without chance to change the name?

Thank's

Regards,

EL
0
Comment
Question by:pander
[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
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 17967894
Try this:

   Dim objApp As Object
   
    Set objApp = CreateObject("Word.Application")
    objApp.Documents.Add , , 0
    objApp.ActiveDocument.Select
    objApp.Selection.TypeText "Your text goes here"
    objApp.ActiveDocument.SaveAs "C:\test.doc"
    objApp.ActiveDocument.Close
    objApp.Quit
    Set objApp = Nothing
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 17967953
if you want to have word open change the code to this:
Dim objApp As Object
   
    Set objApp = CreateObject("Word.Application")
    objApp.Documents.Add , , 0
    objApp.ActiveDocument.Select
    objApp.Selection.TypeText "Your text goes here"
    objApp.ActiveDocument.SaveAs "C:\test.doc"
    objApp.Visible = True
   
0
 
LVL 13

Accepted Solution

by:
Michael_D earned 500 total points
ID: 17967978
oops...  I shouldnt have to remobve this line
Set objApp = Nothing

so this will open word, create new document with given name and leave it open:

Dim objApp As Object
   
    Set objApp = CreateObject("Word.Application")
    objApp.Documents.Add , , 0
    objApp.ActiveDocument.Select
    objApp.Selection.TypeText "Your text goes here"
    objApp.ActiveDocument.SaveAs "C:\test.doc"
    objApp.Visible = True
    Set objApp = Nothing
0
Industry Leaders: 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!

 

Author Comment

by:pander
ID: 17968038
Great !!!

Thank you Michael,

It works good and that's what I was looking for; Another question, Is there any way to disable the toolbar? I want to leave the only "Save" option enabled, if its possible it will be super, if not thats fine.

Regards,
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 17968189
I wold recoment using RTFBox instead of word if you want only limited options.
I never enable/disable toolbars from VB. Also this code uses the "Regular" instance of word - mean if you remove the ttoolbar it will be gone even if user run Word from the start menu

Just my opinion tho...
0
 

Author Comment

by:pander
ID: 17968220
All right Mic, thank you very much.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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