Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBA Print Selected Sheets

Posted on 2012-08-23
2
Medium Priority
?
689 Views
Last Modified: 2012-08-30
I have a form like attached picture.
My wookbook has 4 sheets.
From the form, I want to print selected sheets.

How can I do with VBA?

Thanks!
Untitled.png
0
Comment
Question by:JameMeck
2 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 2000 total points
ID: 38328065
Hi

Try something like

Dim Ctl     As Object
    Dim i       As Long
    Dim n       As Long
    Dim a()
    
    For Each Ctl In Me.Controls
        If TypeName(Ctl) = "CheckBox" Then
            If Ctl.Value Then
                n = n + 1
                ReDim Preserve a(1 To n)
                a(n) = Ctl.Caption
            End If
        End If
    Next
    
    If n Then
        Worksheets(a).Select
        Unload Me
        Worksheets(a).PrintPreview
        'Worksheets(a).PrintOut
    End If

Open in new window


Note: The checkbox caption should be exactly same as your sheet name.

Kris
0
 

Author Closing Comment

by:JameMeck
ID: 38349269
Thanks! I got it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question