Print multiple worksheets to one document

hergy

New Member
Joined
Jun 10, 2017
Messages
8
Hello there,


I setup a vba code to print certain worksheets to one document, but does not work.


Description:


My file consist of 5 worksheets. In each worksheet, i defined print area.


I also put specific sheet named "Printout". In "Printout" sheet, i lined up the 5 worksheets above by placing Checkbox field next (Activex controle), so user can select worksheet he wants to print. Then, user enters in TexBox (Activex controle) a page number that will be insert at the first page of the document. Finally, user clicks on the "Print" button (Activex Controle). After clicking on "Print" Button, a dialog box displays to allow user to choose a printer; user chooses a printer and clicks on Ok button of dialog box, the printout is launched.




The vba code for above is as following (code inserted in the sheet "Printout"):

Code:
 Private Sub PrintoutPageSetup(Feuille, UneOrientation)
'Page setup before printing a worksheet
'UneOrientation=0 do nothing
'UneOrientation=1 force to  landscape
'UneOrientation=2 force to portrait
    On Error Resume Next
    
    Worksheets.Item(Feuille).PageSetup.RightHeader = ""
    Worksheets.Item(Feuille).PageSetup.LeftHeader = "" + Chr(10) & "&G"
    Worksheets.Item(Feuille).PageSetup.CenterFooter = ""
    Worksheets.Item(Feuille).PageSetup.RightFooter = "&P"
    Worksheets.Item(Feuille).PageSetup.LeftFooter = ""
    Worksheets.Item(Feuille).PageSetup.FirstPageNumber = TextBoxNumeroPage.Value
    Worksheets.Item(Feuille).PageSetup.Zoom = False
    If UneOrientation = 1 Then
        Worksheets.Item(Feuille).PageSetup.Orientation = xlLandscape
    End If
    If UneOrientation = 2 Then
        Worksheets.Item(Feuille).PageSetup.Orientation = xlPortrait
    End If
End Sub




Public Sub Printareapage(Feuille, PlageStr As String, Orientation)
'Print an area in a worksheet
    Dim Plage As Range
    
    Call PrintoutPageSetup(Feuille, Orientation)
    NumeroPage = NumeroPage + 1
    Set Plage = Worksheets.Item(Feuille).Range(PlageStr)
    Plage.PrintOut
End Sub




Private Sub CheckBoxReport_Click()
    If CheckBoxReport.Value Then
        CheckBox1.Value = True
        CheckBox2.Value = True
        CheckBox3.Value = True
        CheckBox4.Value = True
        CheckBox5.Value = True
    Else
        CheckBox1.Value = False
        CheckBox2.Value = False
        CheckBox3.Value = False
        CheckBox4.Value = False
        CheckBox5.Value = False
     End If


End Sub




Private Sub PrintButton_Click()
     
    Application.Dialogs(xlDialogPrinterSetup).Show
    
    Application.StatusBar = "Printout in progress..."
    NumeroPage = TextBoxNumeroPage
      


    If CheckBox1.Value = True Then
        Call Printareapage(("Report_1"), "$A$1:$N$90", 0)
    End If
    If CheckBox2.Value = True Then
        Call Printareapage(("Report_2"), "$A$1:$N$90", 0)
    End If
    If CheckBox3.Value = True Then
        Call Printareapage(("Report_3"), "$A$1:$N$90", 0)
    End If
    If CheckBox4.Value = True Then
        Call Printareapage(("Report_4"), "$A$1:$N$90", 0)
    End If
    If CheckBox5.Value = True Then
        Call Printareapage(("Report_5"), "$A$1:$N$90", 0)
    End If
    
    
    Worksheets.Item("Printout").Activate
    Application.StatusBar = ""
End Sub


I tried to print 2 worksheets with PDFCreator, but it's petering out:


1- I get 2 PDF of one page instead of one PDF of two pages.
2- The page numbers do not incremente. Each page has the same number as entered by user before (the consequence of the issue 1 above).
3- The printout is launched even if i click on the button "Cancel" in dialog box.


Help please.


PS: there is a mean to display an alert message when user clicks on Print button without choosing any worksheet first?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top