+ Reply to Thread
Results 1 to 11 of 11

ListBox to Print Range of Sheets

  1. #1
    Registered User
    Join Date
    05-14-2020
    Location
    Washington State
    MS-Off Ver
    2016
    Posts
    61

    ListBox to Print Range of Sheets

    Hi Everyone,

    I copied the following code from an example I found online. I modified it so that it would work in my workbook. I have the listbox in a userform, rather than in a sheet as in the example I took this from. I have a button on my primary (first) sheet which then calls a userform that contains the list box. Everything is working perfectly except the print preview. When I walk through the code I get a "Run-time error '13': type mismatch" error at the line indicated in my code, below. I'm not real familiar with VBA, so I'm finding examples on line and attempting to modify them in my sheet to get the outcome I desire. I have a basic understanding of this type of error after googling it, but don't know how to fix it. Any help is appreciated. I changed the With statement in the code which originally had "ActiveSheet.ListBoxSh" rather than "PrintBox.ListBoxSh". My userform is called PrintBox, so it seemed appropriate to make this change. I don't know if this is part of my problem or not.

    Also, I can select the sheets I want once the userform pops up, but I then want to link the print/print preview to another button on the userform. I think this will require me to rewrite the "Sheets(SheetArray()).PrintPreview/PrintOut so that they are activated when I click the button(s) on the userform. How would I accomplish this?

    Please Login or Register  to view this content.
    Last edited by Proj_Eng; 05-22-2020 at 11:22 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: ListBox to Print Range of Sheets

    You never tell us what you want to do.
    Do you want to populate a ListBox on a UserForm with all the Sheet names of your workbook and when you select one of the sheets you want to preview the PrintRange?
    Has the Print Range been set before?

  3. #3
    Registered User
    Join Date
    05-14-2020
    Location
    Washington State
    MS-Off Ver
    2016
    Posts
    61

    Re: ListBox to Print Range of Sheets

    Jolivanes,

    Sorry, yes, I want to preview the selected sheets in my workbook and then print them by selecting buttons on my userform. Let me know if you need additional information. This is rather new to me.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: ListBox to Print Range of Sheets

    Can you explain the logic of printpreview followed by printing.
    If you're going to print for sure, why printpreview?

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: ListBox to Print Range of Sheets

    See attached.

    You have a UserForm named UserForm1
    Caption: Select Sheets to Preview or Print

    On the UserForm you have
    1) ListBox named lbSheets
    2) CommandButton named cmb1
    3) CommandButton named cmb2
    4) CommandButton named cmb3

    ListBox (lbSheets)
    ListStyle is set to "1 - fmListStyleOption"
    MultiSelect is set to "1 - fmMultiSelectMulti"

    CommandButton (cmb1)
    Name: cmb1
    Caption: Print Preview

    CommandButton (cmb2)
    Name: cmb2
    Caption: Print

    CommandButton (cmb3)
    Name: cmb3
    Caption: Exit

    Sheet1 has a Button (Form Control)
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-14-2020
    Location
    Washington State
    MS-Off Ver
    2016
    Posts
    61

    Re: ListBox to Print Range of Sheets

    I want the option of previewing before I print so that I can review the report before printing.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: ListBox to Print Range of Sheets

    So does the attachment in Post #5 do what you want?

  8. #8
    Registered User
    Join Date
    05-14-2020
    Location
    Washington State
    MS-Off Ver
    2016
    Posts
    61

    Re: ListBox to Print Range of Sheets

    I haven't had a chance to look at it. I will try to get to it, soon, and let you know.

  9. #9
    Registered User
    Join Date
    05-14-2020
    Location
    Washington State
    MS-Off Ver
    2016
    Posts
    61

    Re: ListBox to Print Range of Sheets

    Jolivanes,

    This is awesome! This is just what I was after. Thanks for the help.

  10. #10
    Registered User
    Join Date
    05-19-2020
    Location
    Delhi
    MS-Off Ver
    2013
    Posts
    1

    Re: ListBox to Print Range of Sheets

    Hey, I read your post and this is awesome. Can you help me with a small tweak? I am novice to VBA and thought if I could get some help and it will be highly appreciated.

    Per the same post, I was trying to create a replica but for a different reason.

    Problem -
    I have an excel file with maybe 5 interlinked sheets.
    I want to replicate these sheets maybe 5 more times (30 sheets in total)
    I was able to find a macro which replicates a single sheet multiple times but not all taken together. The issue with this approach is that the linking gets retained to the original tabs and not to the new tabs. But if someway I am able to replicate all the tabs at once, excel modifies the linking to newly created tabs. Per my best estimate, we will need to define the selected worksheets in an array but not too sure.

    What I am looking for is that the macro gives me a list box similar to yours, allows me to select a few sheets (5 or lesser that I already have in the WB, gives me an option of how many times do I want to replicate and then replicates all sheets taken together at once and not individual sheets.

    I have attached a sample copy for reference wherein in different modules you will find all the different codes that I found on the internet.

    In the current version of file, you will find that sheets have been replicated, but sheet "B (2)" for example links back to sheet A, however when you select tabs A, B manually and then create copy of the tabs, you will find that the links are different as can be seen on tabs - "B (3)" and "C (3)" respectively which are the copies created manually.

    Thanks a lot in advance for help.

    Thanks and regards
    Nikhil Kumar
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: ListBox to Print Range of Sheets

    @Nikhil9999176167
    Please read the forum rules, that should say read them again. Rule #4 is of interest to you in this case. Don't just read that rule only. It doesn't hurt to know all of them.
    In your new thread, refer to this thread if you think it helps.
    However, without looking at your attachment, I would say that your explanation has to be a little more understandable for most of the people.
    Good Luck

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Want to set same print range to many sheets
    By PeteABC123 in forum Excel General
    Replies: 2
    Last Post: 11-14-2019, 11:16 AM
  2. Macro Help to print a range of sheets
    By Philipsfn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2017, 10:39 PM
  3. Print Multiple Sheets from a Listbox on a UF as one Print Job
    By craigos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2014, 06:46 AM
  4. userform listbox
    By tsiguy96 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-14-2013, 11:09 PM
  5. Printing sheets from listbox as a single print job
    By longrock in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2011, 07:22 AM
  6. Print only selected sheets from listbox
    By stevemcleod in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2010, 03:24 PM
  7. how do you set or reset the print range for several sheets at a ti
    By Mestrella31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1