?
Solved

How to call MsWord from vb6

Posted on 2006-11-17
6
Medium Priority
?
275 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
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…
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…
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…
Suggested Courses

762 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