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 threadsAuthorRepliesWScarbonnb
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
-
ATT/Yahoo Secure Mail Key
by
Lil88reb
3 hours, 1 minute ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
7 hours, 23 minutes ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
15 hours, 58 minutes ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
1 hour, 24 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
21 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
11 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
2 days, 2 hours ago -
50 years and counting
by
Susan Bradley
23 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 9 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
2 days, 13 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
2 days, 13 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
2 days, 13 hours ago -
OneNote and MS Word 365
by
CWBillow
2 days, 15 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
2 days, 15 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
2 days, 16 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
7 hours, 31 minutes ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
3 days, 3 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
3 days, 3 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
3 days, 12 hours ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
3 days ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
2 days, 1 hour ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
3 days, 21 hours ago -
Apple backports fixes
by
Susan Bradley
3 days, 4 hours ago -
Win 11 24H2 will not install
by
Michael1950
2 days, 1 hour ago -
Advice to convert MBR to GPT and install Windows 11 Pro on unsupported PC
by
Andy M
19 hours, 35 minutes ago -
Photos from iPhone to Win 10 duplicating/reformatting to .mov
by
J9438
2 days, 10 hours ago -
Thunderbird in trouble. Here comes Thundermail
by
Alex5723
22 hours, 4 minutes ago -
Get back ” Open With” in context menus
by
CWBillow
4 days, 12 hours ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
3 days, 4 hours ago -
simple general stupid question
by
WSaltamirano
4 days, 10 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.