I want to be able to select the worksheets to print. The attached program works with the exception that it always prints the last worksheet even if it hasn’t been checked. Can anyone help?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Print Worksheets (VBA Excel)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Print Worksheets (VBA Excel)
- This topic has 8 replies, 3 voices, and was last updated 22 years, 5 months ago.
AuthorTopicViewing 2 reply threadsAuthorReplies-
WSMary K
AskWoody Lounger -
WSbandido
AskWoody Lounger -
WSMary K
AskWoody Lounger
-
-
WScarbonnb
AskWoody LoungerNovember 10, 2002 at 3:03 pm #630601Mary,
The problem is with this chunk of code towards the bottom.
PrintDlg.Buttons("Button 2").BringToFront PrintDlg.Buttons("Button 3").BringToFront CurrentSheet.Activate If SheetCount 0 Then If PrintDlg.Show Then
Using CurrentSheet.Activate activates seelcts the last sheet all the time.
So if you comment out that line:
PrintDlg.Buttons("Button 2").BringToFront PrintDlg.Buttons("Button 3").BringToFront 'CurrentSheet.Activate If SheetCount 0 Then If PrintDlg.Show Then
The it should work as expected. If you want me to post the whole routine, just let me know.
-
WSMary K
AskWoody Lounger -
WScarbonnb
AskWoody LoungerNovember 10, 2002 at 3:38 pm #630609Quite right you are. I guess I need to do better checking before I post replies
The problem is that when you do the CurrentSheet.Activate, you are selecting the last sheet.
Then when you loop through the checkboxes on the form, you are adding to the selection, which includes the last sheet. So what you have to do, is replace the current selection when you select the worksheet that is checked, and just add to it when you get to the rest. TO do that you will need to add a boolean flag to indicate if you have selected one yet. Add:
Dim bolFirstOne As Boolean
at the top and then replace:
If cb.Value = xlOn Then Worksheets(cb.Caption).Select Replace:=False End If
with:
If cb.Value = xlOn Then 'Check to see if we have selected atleast one sheet yet If bolFirstOne = False Then 'No, not yet ' Replace the current seelction Worksheets(cb.Caption).Select Replace:=True 'Set the flag to indicate now we have set the first one bolFirstOne = True Else 'Now that we have selected the first one, just add to the selection Worksheets(cb.Caption).Select Replace:=False End If End If
You can leave the CurrentSheet.Activate line there, or you can comment it out. It doesn’t matter. I tested it with it uncommented. And yes I did some more testing before posting this
-
WSMary K
AskWoody Lounger -
WScarbonnb
AskWoody Lounger
-
-
-
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
1 hour, 9 minutes ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
1 hour, 38 minutes ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
12 hours, 34 minutes ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
7 hours, 18 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
3 hours, 33 minutes ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
33 minutes ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
16 hours, 24 minutes ago -
The time has come for AI-generated art
by
Catherine Barrett
1 day, 1 hour ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
6 hours, 8 minutes ago -
23 and you
by
Max Stul Oppenheimer
13 hours, 22 minutes ago -
April’s deluge of patches
by
Susan Bradley
17 hours, 33 minutes ago -
Windows 11 Windows Updater question
by
Tex265
23 hours, 20 minutes ago -
Key, Key, my kingdom for a Key!
by
RetiredGeek
1 day, 22 hours ago -
Registry Patches for Windows 10
by
Drcard:))
2 days, 2 hours ago -
Cannot get line length to NOT wrap in Outlining in Word 365
by
CWBillow
1 day, 9 hours ago -
DDU (Display Driver Uninstaller) updates
by
Alex5723
18 hours, 37 minutes ago -
Align objects on a OneNote page
by
CWBillow
2 days, 8 hours ago -
OneNote Send To button?
by
CWBillow
2 days, 8 hours ago -
WU help needed with “Some settings are managed by your organization”
by
Peobody
2 days, 17 hours ago -
No Newsletters since 27 January
by
rog7
22 hours, 4 minutes ago -
Linux Mint Debian Edition 7 gets OEM support, death of Ubuntu-based Mint ?
by
Alex5723
1 day, 18 hours ago -
Windows Update “Areca Technology Corporation – System – 6.20.0.41”
by
Bruce
1 day, 16 hours ago -
Google One Storage Questions
by
LHiggins
1 day ago -
Button Missing for Automatic Apps Updates
by
pmcjr6142
1 day, 7 hours ago -
Ancient SSD thinks it’s new
by
WSila
1 day, 22 hours ago -
Washington State lab testing provider exposed health data of 1.6 million people
by
Nibbled To Death By Ducks
3 days, 8 hours ago -
WinRE KB5057589 fake out
by
Susan Bradley
18 hours, 53 minutes ago -
The April 2025 Windows RE update might show as unsuccessful in Windows Update
by
Susan Bradley
2 days, 16 hours ago -
Firefox 137
by
Charlie
15 minutes ago -
Whisky, a popular Wine frontend for Mac gamers, is no more
by
Alex5723
3 days, 20 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.