Solved

How to call MsWord from vb6

Posted on 2006-11-17
6
264 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
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Michael_D
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:pander
Comment Utility
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
Comment Utility
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
Comment Utility
All right Mic, thank you very much.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now