tmckissick
New Member
- Joined
- Oct 1, 2015
- Messages
- 1
Hi all,
I have a spreadsheet that has a summary tab with a list of customer, addresses, etc., and another tab that creates invoices from the summary. I wrote a macro that cycles through the table and creates and prints invoices to the default printer.
That part works fine.
I am trying to add some code that changes the default printer, prints the file to pdf, then restores the default printer. It does not work:
Sub PrintAll()
Dim strValidationRange As String
Dim rngValidation As Range
Dim rngDepartment As Range
Dim STDprinter As String
Application.ScreenUpdating = False
strValidationRange = Range("A10").Validation.Formula1
Set rngValidation = Range(strValidationRange)
For Each rngDepartment In rngValidation.Cells
Range("A10").Value = rngDepartment.Value
ActiveSheet.PrintOut
Next
STDprinter = Application.ActivePrinter
Application.ActivePrinter = "Microsoft Print to PDF"
ActiveSheet.PrintOut
strValidationRange = Range("A10").Validation.Formula1
Set rngValidation = Range(strValidationRange)
For Each rngDepartment In rngValidation.Cells
Range("A10").Value = rngDepartment.Value
ActiveSheet.PrintOut
Application.ActivePrinter = STDprinter
Next
Application.ScreenUpdating = True
End Sub
Any Suggestions?
I have a spreadsheet that has a summary tab with a list of customer, addresses, etc., and another tab that creates invoices from the summary. I wrote a macro that cycles through the table and creates and prints invoices to the default printer.
That part works fine.
I am trying to add some code that changes the default printer, prints the file to pdf, then restores the default printer. It does not work:
Sub PrintAll()
Dim strValidationRange As String
Dim rngValidation As Range
Dim rngDepartment As Range
Dim STDprinter As String
Application.ScreenUpdating = False
strValidationRange = Range("A10").Validation.Formula1
Set rngValidation = Range(strValidationRange)
For Each rngDepartment In rngValidation.Cells
Range("A10").Value = rngDepartment.Value
ActiveSheet.PrintOut
Next
STDprinter = Application.ActivePrinter
Application.ActivePrinter = "Microsoft Print to PDF"
ActiveSheet.PrintOut
strValidationRange = Range("A10").Validation.Formula1
Set rngValidation = Range(strValidationRange)
For Each rngDepartment In rngValidation.Cells
Range("A10").Value = rngDepartment.Value
ActiveSheet.PrintOut
Application.ActivePrinter = STDprinter
Next
Application.ScreenUpdating = True
End Sub
Any Suggestions?