+ Reply to Thread
Results 1 to 7 of 7

Debug Error bugging me!!

  1. #1
    Registered User
    Join Date
    12-10-2003
    Posts
    41

    Debug Error bugging me!!

    OK,..This one is driving me nuts!!!

    I created this form in Excel that contains 7 different tabbed worksheets within it.
    So far so good!

    I have a button that when pressed, automatically prints out all 7 worksheets at once to the printer!

    Here's the problem. I entered the code as such (see below) that it DOES work,..but if anyone changes the name of the workbook,..they get a debug error message!!! Is there something I can add in the lines of code so that they can name the workbook anything they want and it will still print. I tried *.xls in place of the Project Workbook.xls assuming "*" meant wildcard,..but it didn't work.

    As other folks use this form,..they often change the name of the file or workbook to Project Workbook 2 or 3 or they add a date or something and then it throws it off.

    Application.Run "'Project Workbook.xls'!Print_Overview"
    Application.Run "'Project Workbook.xls'!Print_Contact_List"
    Application.Run "'Project Workbook.xls'!Print_Issue_Tracker"
    Application.Run "'Project Workbook.xls'!Print_Site_List"
    Application.Run "'Project Workbook.xls'!Print_Project_Plan"
    ActiveWindow.SmallScroll Down:=3
    Application.Run "'Project Workbook.xls'!Print_Exec_Summary"
    Application.Run "'Project Workbook.xls'!Print_Closeout"
    ActiveWindow.SmallScroll Down:=3

    Thanks,

    Todd
    Todd P. Dolce

  2. #2
    Registered User pikus's Avatar
    Join Date
    12-06-2003
    Location
    Philadelphia
    Posts
    4
    Try this out and let me know if you have any problems. - pikus

    For x = 1 To Worksheets.Count
    Worksheets(x).PrintOut
    Next x
    I want to live 'til I die. No more. No less.

  3. #3
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    You should be able to use
    ThisWorkbook (outside the quotes) which will find the worksheets in the workbook which contians the macro code for printing.
    As long as people don't go changing the worksheet names this should work for you.
    If you think they may start changing worksheet names you can call the worksheets by relative reference.
    Sheets(1) , Sheets(2) , etc...

    Give this a try

    Application.Run "'" & ThisWorkbook & ".xls'!Print_Overview"

    repeat for the rest of your worksheets.
    untested but a starting place.

    HTH

    B

  4. #4
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    If you want to print <ALL> sheets in the workbook:

    Sub PrintAll()
    ActiveWorkbook.PrintOut
    End Sub

    is the code to use.

    It doesn't care the name of the sheets or the workbook!

    HTH
    Bruce
    The older I get, the better I used to be.
    USA

  5. #5
    Registered User
    Join Date
    12-10-2003
    Posts
    41
    If you want to print <ALL> sheets in the workbook:

    Sub PrintAll()
    ActiveWorkbook.PrintOut
    End Sub

    is the code to use.

    It doesn't care the name of the sheets or the workbook!

    HTH


    Uh,...this did the trick!!! Thanks guys!! I'm off and running!!!

    td
    Last edited by TPD; 04-26-2005 at 03:28 PM.

  6. #6
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    First of all do you want to print out all the worksheets or just the ones named?
    Secondly the code you posted won't work as is because you have the lines with the print statements commented out (with the single quote ' at the beginning).

    If you want all worksheets of the active workbook printed then use Bruce's suggestion.
    If you want just the first several worksheets printed you can modify Pikus code and loop from 1 to (highest worksheet you want printed) OR loop from (first worksheet you want printed) to (highest worksheet you want printed)

    Keep you hair and go pull out her's

  7. #7
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    Todd: Glad it worked for you. Hunt down Catherine and rub her nose in it then call Hairclub for Men!

    Cheers!

    Bruce

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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