Solved

How to call MsWord from vb6

Posted on 2006-11-17
6
270 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
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!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 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…

724 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