J
JayM
I need help tidying up my code or making it easier to reference.
I have a few macros that do similar things each one sets a different paper
tray on the printer.
You will see that I have written it so that it checks the printers location
so it knows which printer tray to select.
Is there a way I can change it to references the printers once instead of in
each macro.
Many thanks for your help in advance
Code:Sub Print_LH()
sLocation = GetPrinterDetails.Location
'HP Printers
If InStr(sLocation, "TH20194") Or InStr(sLocation, "TH20485") Or _
InStr(sLocation, "TH30412") Or InStr(sLocation, "TH20192") Or _
InStr(sLocation, "TH20482") Or InStr(sLocation, "TH30413") Or _
InStr(sLocation, "TH20484") Or InStr(sLocation, "TH20193") Or _
InStr(sLocation, "TH20195") Or InStr(sLocation, "TH30142") Or _
InStr(sLocation, "TH20164") Or InStr(sLocation, "TH30041") Or _
InStr(sLocation, "TH20165") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
'Sharp MX4500 Printers
ElseIf InStr(sLocation, "TH30441") Or InStr(sLocation, "TH30449") Or _
InStr(sLocation, "TH30143") Or InStr(sLocation, "TH30461") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
'Sharp 450 Printers
ElseIf InStr(sLocation, "TH30141") Or InStr(sLocation, "TH30442") Or _
InStr(sLocation, "TH30143") Or InStr(sLocation, "TH30245") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
Else: MsgBox "The Printer you are trying to use is either not networked or
incorrectly set up." _
& vbCrLf & "In the first instance please use the File|Print Menu (Ctrl
P)." _
& vbCrLf & "In the second instance please contact IT on Ext 109. " &
sLocation, vbOKOnly
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End Sub
I have a few macros that do similar things each one sets a different paper
tray on the printer.
You will see that I have written it so that it checks the printers location
so it knows which printer tray to select.
Is there a way I can change it to references the printers once instead of in
each macro.
Many thanks for your help in advance
Code:Sub Print_LH()
sLocation = GetPrinterDetails.Location
'HP Printers
If InStr(sLocation, "TH20194") Or InStr(sLocation, "TH20485") Or _
InStr(sLocation, "TH30412") Or InStr(sLocation, "TH20192") Or _
InStr(sLocation, "TH20482") Or InStr(sLocation, "TH30413") Or _
InStr(sLocation, "TH20484") Or InStr(sLocation, "TH20193") Or _
InStr(sLocation, "TH20195") Or InStr(sLocation, "TH30142") Or _
InStr(sLocation, "TH20164") Or InStr(sLocation, "TH30041") Or _
InStr(sLocation, "TH20165") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
'Sharp MX4500 Printers
ElseIf InStr(sLocation, "TH30441") Or InStr(sLocation, "TH30449") Or _
InStr(sLocation, "TH30143") Or InStr(sLocation, "TH30461") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
'Sharp 450 Printers
ElseIf InStr(sLocation, "TH30141") Or InStr(sLocation, "TH30442") Or _
InStr(sLocation, "TH30143") Or InStr(sLocation, "TH30245") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
Else: MsgBox "The Printer you are trying to use is either not networked or
incorrectly set up." _
& vbCrLf & "In the first instance please use the File|Print Menu (Ctrl
P)." _
& vbCrLf & "In the second instance please contact IT on Ext 109. " &
sLocation, vbOKOnly
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End Sub