PDA

View Full Version : Word 2007 Print macro help



Tooms
06-11-2009, 07:19 AM
Hi guys, hope you can help us.

My firm is running computers with Microsoft XP professionnal SP2 and Office 2007.

I am trying to set up a set of macros to deal with the printing.

Ideally we need 3 macros. one that will print the whole letter only on plain paper (tray 3), one that will print page 1 on headed paper (tray 2) and the rest on plain paper, and one that will, with one button, do a full copy of everything and so it will do both of the above.

We have a HP laserjet attached to the network so everyone is using the same printer.

I keep trying to record a macro but I am not very good.

On the print dialogue box, i have set up under properties, printing shortcuts called "letterhead" and "plain" which if you select them yourself, work perfectly.

But I cannot get a macro to chose them when trying to record one. :dunno

I am not very good with macros so I have no clue where to start to write one from scratch to do this.

This is what I have come up with (very basic I know):


Sub fullprint()
'
' fullprint Macro
'
'
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

End Sub
Sub plainprint()
'
' plainprint Macro
'
'
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
Sub headedprint()
'
' headedprint Macro
'
'
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub


If anyone has any ideas, that would be very gratefully recieved.

Thanks

Nelviticus
06-15-2009, 02:19 AM
This should do it:
Public Sub PrintPlain()

Dim OriginalTray As String

With Options

' Store original tray setting
OriginalTray = .DefaultTray

' Change to tray 3 and print whole document
' with default settings
.DefaultTray = "Tray 3"
Application.PrintOut

' Restore original tray
.DefaultTray = OriginalTray

End With

End Sub

Public Sub PrintHeaded()

Dim OriginalTray As String

With Options

' Store original tray setting
OriginalTray = .DefaultTray

' Change to tray 2 and print first page
' with default settings
.DefaultTray = "Tray 2"
Application.PrintOut Pages:="1"

' Change to tray 3 and print remaining
' pages with default settings
.DefaultTray = "Tray 3"
Application.PrintOut Pages:="2-9999"

' Restore original tray
.DefaultTray = OriginalTray

End With

End Sub

Public Sub PrintPlainAndHeaded()

Call PrintPlain
Call PrintHeaded

End Sub
You need to get the tray names exactly right though - record a macro of you going into Word's options, going to the 'Advanced' group and changing the 'Default Tray' in the 'Print' section. Choose tray 2 and see what name the macro has recorded, then do it again and choose tray 3. Change the values in my code if they're different to your actual tray names.

Regards

Tooms
07-17-2009, 08:38 AM
Thanks for that. I have given it a go. Unfortunately the headed print does not work.

it prints out the whole letter on headed, then all of it again on plain.

Any ideas ?

Nelviticus
07-17-2009, 08:45 AM
I'm guessing that you have used incorrect values for the trays. If you use something invalid it won't give an error, it will just use the printer's default tray.

Record a macro like I mentioned at the end and have a look at what values it uses for the tray names.

mdmackillop
07-17-2009, 09:04 AM
Have a look at this KB Item. I've been using this ever since I created it!
http://www.vbaexpress.com/kb/getarticle.php?kb_id=240

Tooms
07-21-2009, 03:34 AM
mdmackillop

Thanks for your help. However I am completely incapable of doing that. I thought I had got it, but instead everytime I try to run the macro, it says Run Time Error '424' and if you hit debug, it shows the macro with the "PrintSelector.Show" part highlighted in yellow.

I have no idea how to change this.

Nelviticus, i am going to go try your idea again now.

Thanks again for the help guys