Word

  • Thread starter Thread starter Mason
  • Start date Start date
M

Mason

I have a macro to print about 14 access reports, but
there is a word file that is associated which I would
like to have printed when I run the macro. Is there a
way to write VBA code to open a word document print it
and close it? Thanks
 
Since no one has responded to you yet I figured I'd
attempt to send you in the right direction with this. I
have never done this before but I looked it up in my VBA
for Microsoft Office 2000 Unleashed text by Paul
McFedries. It seems that what you are looking for starts
on p.447. It involves using the Shell command to open the
application and then using the SendKeys command to send
keystrokes to the application.

I hope that gets you starting in figuring out your problem.
 
Is there a
way to write VBA code to open a word document print it
and close it?

This is routing OLE automation code: just remember that what follows has
not been checked: you'll need to look up the functions in Word VBA help
files:


' get a new Word instance
' it's harder to find an existing running instance, but it
' doesn't matter so don't bother
'
' On the other hand, if you set a reference to Word library
' in VBEditor, you can just use Dim as New instead
Set appWord = GetObject(, "Word.Application")

' This line is optional, but it makes the user feel better if
' the application actually appears on screen. GetObject always
' leaves the object invisible
appWord.Visible = True

' Open the document: you can use this method to set passwords,
' readonly status and so on
Set doc = appWord.Documents.Open("c:\docs\mydoc.doc")

' I haven't used this method much: you can choose which pages
' to print and so on
doc.PrintOut

' Tidying up
doc.Close
appWord.Quit

' All done


Hope that helps


Tim F
 
Back
Top