Answer the question
In order to leave comments, you need to log in
Printing specified VBA pages (checkbox). How?
Good afternoon.
Strongly do not offend smart words.
I want to print certain pages, depending on the checked checkbox . I marked
3 checkboxes, pressed print... On
the
first page joxi.ru/RmzqZ3JH09O0Nr
(I'm first day at this)
Dim strPage As String
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
'Application.PrintOut Pages:="1,2"
strPage = "2"
ElseIf CheckBox1.Value = False Then
strPage = ""
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
'Application.PrintOut Pages:="1,2"
strPage = "3"
ElseIf CheckBox2.Value = False Then
strPage = ""
End If
End Sub
Private Sub CommandButton1_Click()
'MsgBox strPage
Application.PrintOut Pages:=strPage
End Sub
Answer the question
In order to leave comments, you need to log in
Dim strPages As String
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
strPages = strPages & "2"
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
strPages = strPages & "3"
End If
End Sub
Private Sub CommandButton1_Click()
Application.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPages
'MsgBox strPages
End Sub
The Pages parameter specifies the sheet numbers in the form "2, 3" (for printing sheets 2 and 3).
Sub PrintSelectedPages()
Dim strPages As String
strPages = strPages & IIf(CheckBox1.Value, IIf(strPages = "", "", ",") & "2", "")
strPages = strPages & IIf(CheckBox2.Value, IIf(strPages = "", "", ",") & "3", "")
If Not strPages = "" Then Application.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPages
End Sub
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question