Peter Davison
Active Member
- Joined
- Jun 4, 2020
- Messages
- 451
- Office Version
- 365
- Platform
- Windows
Hi All,
I have this VBA Code to print a report and wanted to know if I could add code that would allow the user to choose if they wanted to print on both sides (I think I have achieved this part with my code in bold currently turned into a comment).
However, I'm not sure how to add code at the end to make the printer action the choice?
If anyone has any ideas that would be great.
Sub SetPrintSettingsAndPrintAddNewStore()
Dim ws As Worksheet
Dim lastRow As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Add New Store")
' Find the last row with data in column B
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
' Prompt user for print mode
'printBothSides = MsgBox("Do you want to print on both sides?", vbYesNo) = vbYes
' Set the print range
'If printBothSides Then
ws.PageSetup.PrintArea = "$B$1:$L$" & lastRow
'Else
'ws.PageSetup.PrintArea = "$B$1:$L$" & lastRow * 2 ' Double the last row for duplex printing
'End If
' Set the orientation to Landscape
ws.PageSetup.Orientation = xlLandscape
' Set titles row
ws.PageSetup.PrintTitleRows = "$11:$11"
' Set margins
With ws.PageSetup
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.1)
.BottomMargin = Application.InchesToPoints(0.1)
End With
' Print the document
ws.PrintOut
End Sub
I have this VBA Code to print a report and wanted to know if I could add code that would allow the user to choose if they wanted to print on both sides (I think I have achieved this part with my code in bold currently turned into a comment).
However, I'm not sure how to add code at the end to make the printer action the choice?
If anyone has any ideas that would be great.
Sub SetPrintSettingsAndPrintAddNewStore()
Dim ws As Worksheet
Dim lastRow As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Add New Store")
' Find the last row with data in column B
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
' Prompt user for print mode
'printBothSides = MsgBox("Do you want to print on both sides?", vbYesNo) = vbYes
' Set the print range
'If printBothSides Then
ws.PageSetup.PrintArea = "$B$1:$L$" & lastRow
'Else
'ws.PageSetup.PrintArea = "$B$1:$L$" & lastRow * 2 ' Double the last row for duplex printing
'End If
' Set the orientation to Landscape
ws.PageSetup.Orientation = xlLandscape
' Set titles row
ws.PageSetup.PrintTitleRows = "$11:$11"
' Set margins
With ws.PageSetup
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.1)
.BottomMargin = Application.InchesToPoints(0.1)
End With
' Print the document
ws.PrintOut
End Sub