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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide & Print a Word Document from within VBA 1

Status
Not open for further replies.

delboy1295

Technical User
Nov 27, 2003
7
0
0
GB
I wonder if I may call on your expertise to help me with a problem.

I'm developing an app in VBA.

After a particular event, I want to take various data and transfer it to a Word Template. I have set up bookmarks and everything works fine.

At present the document is displayed and can then be printed. I would prefer that the document is not displayed, but two copies are simply printed using the embedded data.
I would also like save the document using a value from one of the fields.

I would appreciate any help you can give me.

Thanking you in anticipation!
 
You're going to get better help in the VBA Visual Basic for Applications (Microsoft) Forum
forum707
 
The best way to learn things in VBA is to turn on the macro recorder and review your keystrokes.

Are you running this Word document from another app, like Excel?

If so, then it goes something like this:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' WORD PRINT VARIABLES
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public WordApp As New Word.Application
Public Doc As Word.Document

Public Sub OpenPrintWord()
Dim vWordFile As String
vWordFile = App.Path + "\Text.doc"
WordApp.Documents.Open FileName:=vWordFile, ReadOnly:=True
WordApp.Visible = False
WordApp.ActiveDocument.PrintOut
WordApp.ActiveDocument.SaveAs ("Filename.doc")
WordApp.ActiveDocument.Close (wdDoNotSaveChanges)
WordApp.Quit
Set WordApp = Nothing
End Sub
 
Many Thanks Rogue Poet!
I'm running this from an Accounting Program that allows me to 'hook' into it when certain events occur.

What you've suggested looks fine, but I havent had cjance to try it yet!

Thanks Again

Delboy1295
 
You mentioned that you would like 2 copies to print, so you need to make your PRINTOUT statement look like this:

WordApp.ActiveDocument.PrintOut Copies:=2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top