The "Print selected Sheets macro" prints unwanted last page

DutchKevin

Board Regular
Joined
Apr 13, 2011
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hello All,
I'm very impressed and happy with this code I found on the J-Walk website :pray:
http://spreadsheetpage.com/index.php/tip/displaying_a_menu_of_worksheets_to_print/

It lets me select and print sheets from a large workbook. Very userfriendly.

I now use the suggested code at the bottom (from Aaron Blood) to have all pages print as one document, which is very convenient if printing it to a PDF-printer--> One file :biggrin:.
However, the code somehow always adds the last sheet to the print, even when that last slide is not selected in the checkbox list.

If the last sheet is empty, this does not occur.... :???:
Does anyone see a sollution for this?
My feeling is that it might have something to do with the part about :
' Add a temporary dialog sheet but i don't see the workaround.
I would not prefer to have an empty sheet at the back. This is because an other macro is used to copy-add new sheets, at the back of the range logically, from a template-sheet.

For complete code, please see above link.

Any help/advise is greatly appreciated.

Kevin
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi,

I tried the modification and got the same result as you. I have no idea why it prints the extra page so I added a valid checkbox count and it seems to print only those pages selected now.


Code:
'   Display the dialog box
    CurrentSheet.Activate
    Application.ScreenUpdating = True
    If SheetCount <> 0 Then
        If PrintDlg.Show Then
            num = 0
            For Each cb In PrintDlg.CheckBoxes
                If cb.Value = xlOn Then
                 num = num + 1
                 Worksheets(cb.Caption).Select Replace:=False
                End If
            Next cb
            
      If num = 0 Then
       MsgBox "No sheets selected for printing"
    Else
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=num, Copies:=1
    End If
    End If
    
    Else
        MsgBox "All worksheets are empty."
    End If
 
Last edited:
Upvote 0
Hi Daverunt
This works nicely. Thanks for taking the time to look into it and finding a sollution. I've implemented it right away and the problem is indeed solved now.:cool:

Many thanks again
Kevin
 
Upvote 0
Hi Daverunt, we might have been a bit to optimistic.
I tried it with one sheet consisting of more pages. So only 1 checkbox, but with your addition in code it prints only 1 page, where i would like to see more...
I feel we're close but not yet there. Any other ideas? :confused:

thanks
Kevin
 
Upvote 0
I think the Collate:=True is supposed to work but doesn't appear to on my PC.

Code:
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=num, Copies:=1, Collate:=True

So I am out of ideas!
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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