Need Help Printing a Word Document from an Excel Macro...


Posted by Bill Tanner on December 12, 1999 2:51 PM

I am not a programmer but I am trapped in a project
that requires programming. I've done okay but it's a good thing that
computers have gotten so fast because my code is so clunky that it would
choke an older computer or a programmer of any age.

Anyway, I am trying to print a Word document from an Excel macro. I did
a search on this site and saw one suggestion on the message board but it
didn't work for me. The code I used reads as follows:

Sub PrintWordDoc()
Dim AppWord As Word.Application
Set AppWord = GetObject("C:\My Documents\Word Documents\filename.doc")
With AppWord
.ActiveDocument.PrintOut Background:=False
.Quit SaveChanges:=False 'Quit & close without changes
End With
Set AppWord = Nothing 'release reference to it
End Sub

My problem is that I get a "Compile Error: User-defined type not
defined".

Would somebody please be so kind as to suggest a fix?

Thank you.

Bill Tanner

Posted by Tom Morales on December 13, 1999 3:17 PM

Bill
First, you need to add the Word objects to your Excel VBA reference library. In your VBA editor, Go to "tools", then "references", and select Microsoft Word Object Library. That will get you past the first hurdle.

Next, try this code:
Sub PrintWordDoc()
Dim AppWord As Word.Application
Set AppWord = CreateObject("Word.Application.8")
AppWord.Visible = True 'This could be false, also
Set mydoc = Documents.Open(FileName:="C:\whatever.doc")
With AppWord
.ActiveDocument.PrintOut Background:=False
.Quit SaveChanges:=False 'Quit & close without changes
End With
Set AppWord = Nothing 'release reference to it
End Sub

Good Luck,
tom

Posted by Bill Tanner on December 13, 1999 5:05 PM

Ohhhh Thank you....

I was preparing to input probably 200 pages of MS Word text (in maybe 50 files) into Excel spreadsheets and then format them to get them as close as possible to their Word counterparts. This would have been a major pain in the pattutti and I tell you this only to give you a sense as to how grateful I am.

Bill Tanner




Posted by Craig Seymour on April 13, 2000 5:03 AM

Need Help Creating and Printing a Table in a Word Document from an VBA Module

I am having problems creating a Word table within a VB program. Can you help? Thanks,

Craig