Need VBA help

G

Guest

in my macro, I print several tabs and they print a certain order. I'm trying
to open a word doc and print it to my color printer. The macro changes the
printer to the color one, but when I run the macro, the word doc doesn't
print at all. Any help is appreciated. I have created the reference under
(tools/reference). My code is below: Thanks.

On Error Resume Next
Application.ActivePrinter = "HP C LaserJet 4550N PCL6 on Ne01:"
If Err.Number = 1004 Then
Application.ActivePrinter = "hp c Laserjet 4550N PCL6 on Ne02:"
Err.Clear
End If
Sheets("Letter").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Cover").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Agreement").Select
Dim WD As Object
Set WD = CreateObject("Word.Application")
WD.Documents.Open ("G:\CONTRACT\Contract Terms\macro\macro Jun08_04
Warranty&Maintenance Ts&Cs.C.3 Jun2004 FINAL.doc")
WD.ActiveDocument.PrintOut
WD.Application.Quit SaveChanges:=wdDoNotSaveChanges
Set WD = Nothing
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Agreement").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Cover").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Agreement").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
 
S

Sharad

Hi Brad,

1. Is the path of the word document correct? The last folder name
appears to be too long.

2. If it is correct then then just above ' Sheets ("Letter").Select ',
add ' On Error GoTo 0 '.
Then run the code. It will give error message. Click on Debug and find
out which line is causing the error.
Post that line.

Sharad
 
G

Guest

Sharad,

I have fixed the problem. I moved the Quit Document towards the end, it
seemed like it was exiting the doc before the printing could finish. However,
I am running into one more problem. When the macro opens the word doc, it is
now asking me to select if I want read only and 2 other options. Is there any
code that I can enter that will automatically select read only? Thanks.
 
D

Dave Peterson

I started up word and opened a file readonly and recorded a macro when I did it.

I got this bit of code:

Documents.Open FileName:="Doc2.doc", ConfirmConversions:=False, ReadOnly:= _
True, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="" _
, Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto

So I bet this would work for you:

WD.Documents.Open "G:\CONTRACT\Contract Terms\macro\" _
& "macro Jun08_04 Warranty&Maintenance Ts&Cs.C.3 Jun2004 FINAL.doc", _
readonly:=true

(well, if I got the spacing correct in your filename!)

========
I've turned off MSWord's printing in the background.

It may make it easier for your process, too:

Inside MSWord:
Tools|Options|Print tab|Uncheck background printing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top