Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to open an existing Word document from a VB application. 2

Status
Not open for further replies.

unfrozen

Programmer
Jun 8, 1999
1
US
I'm trying to identify the quickest way to open a Word document from within a VB application. I believe that GetObject is the way to go but am having a few problems with it. If anyone has some code to share or can point me to an example I would appreciate it very much.

Thanks [sig][/sig]
 
Set a reference to the Word library in Project / references and then dim an object as:

Dim objWord As New Word.Application

and use the object to open your document:

objWord.Documents.Open "c:\aa\word.doc"
objWord.Visible = True

Note this will not open 'inside' your application, it will open Word and open the document. [sig]<p>Simon<br>[/sig]
 

Make a reference to &quot;Microsoft Word 8.0 Object Library&quot; then try this code:

Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document

Set objWordApp = New Word.Application
objWordApp.Visible = False
Set objWordDoc = objWordApp.Documents.Open(yourDoc)
objWordApp.Visible = True
objWordApp.WindowState = wdWindowStateMaximize

I hope this helps!
[sig]<p> Tarek<br><a href= > </a><br>The more I learn, the more I need to learn![/sig]
 

Simon,

It looks like we submitted our posts at the same time. Didn't mean to be repetitive.

While I'm here, let me add this:

If you declare the &quot;Application&quot; and &quot;Document&quot; variables globally with events then you can get additional info such as when the word app is closed or when a document is changed, etc.

Private WithEvents objWordApp As Word.Application
Private WithEvents objWordDoc As Word.Document
[sig]<p> Tarek<br><a href= > </a><br>The more I learn, the more I need to learn![/sig]
 
VB400

No worries. It is always good to get someone elses views. [sig]<p>Simon<br>[/sig]
 
Hi! VB400

I did the coding for printing the report in the txt file.
But now I want to do it in MS Word.
I made reference to &quot;Microsoft Word 9.0 Object Library&quot;
In the reference &quot;Microsoft Word 8.0 Object Library&quot; is not there.

Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document

Set objWordApp = New Word.Application
(giving error to this line--Invaild procedure call)

What should i do.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top