S
S
sHARek2018-05-31 17:22:34
Visual Basic
sHARek, 2018-05-31 17:22:34

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

What should be passed (string, number) and how to correctly pass page numbers to Application.PrintOut Pages:="" (glued variable strPage , that is, with two checkboxes checked, it should be something like 23. Concatenation must be done somehow, then built-in function to divide by 2.3 Brains are not enough)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sHARek, 2018-06-01
@sHARek

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

Requires parameter Range:=wdPrintRangeOfPages
And so it will do :D

L
lvv85, 2018-06-01
@lvv85

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 question

Ask a Question

731 491 924 answers to any question