Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default set up a command button to print multiple workbook

i put a commad button on a worksheet o i could hit it t print multiple
workbooks.
it prints only a few thengives me an error code of 9.cannot fix
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default set up a command button to print multiple workbook

hi
post your code and point out were the error occurs.

Regards
FSt1

"casper" wrote:

i put a commad button on a worksheet o i could hit it t print multiple
workbooks.
it prints only a few thengives me an error code of 9.cannot fix

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default set up a command button to print multiple workbook

It is hard to give an answer without seeing the code in question, but
an error 9 is a "subscript out of range" error. This occurs when you
are attempting to access a member of a collection when that member
does not exist. For example,

Worksheets("Sheet6").PrintOut

will throw an error 9 if there is no sheet named "Sheet6" because you
are attempting to access an item in the Worksheets collection that
doesn't exist.

If the problem is indeed a non-existent worksheet, you can use the
following function to test if the sheet exists:

Function SheetExists(SheetName As String, _
Optional WB As Workbook) As Boolean
On Error Resume Next
SheetExists = CBool(Len(IIf(WB Is Nothing, ThisWorkbook, WB). _
Worksheets(SheetName).Name))
End Function


Then, in your code, do something like

If SheetExists("Sheet6") = True Then
Worksheets("Sheet6").PrintOut
Else
' sheet does not exist
End If


If you need to test whether a workBOOK rather than a workSHEET exists,
use the following function:

Function WorkbookExists(WBName As String) As Boolean
Dim WB As Workbook
On Error Resume Next
For Each WB In Application.Workbooks
If StrComp(WB.Name, WBName, vbTextCompare) = 0 Or _
StrComp(WB.FullName, WBName, vbTextCompare) = 0 Then
WorkbookExists = True
Exit Function
End If
Next WB
WorkbookExists = False
End Function

Here, WBName can be either just the name (e.g., "Book1.xls") or the
full file path of the workbook name (e.g., "C:\Folder\Test\Book1.xls")


You'd use this code like


If WorkbookExists("Book1.xls") = True Then
' workbook exists. do something
Else
' workbook does not exist. do something else.
End If


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 27 Aug 2009 14:55:01 -0700, casper
wrote:

i put a commad button on a worksheet o i could hit it t print multiple
workbooks.
it prints only a few thengives me an error code of 9.cannot fix

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
print 20 cells with a command button [email protected] Excel Discussion (Misc queries) 5 February 3rd 08 05:57 PM
Print from Command Button Range Garyw Excel Discussion (Misc queries) 8 May 3rd 07 09:17 PM
command button print RKS Excel Discussion (Misc queries) 0 March 23rd 07 10:59 AM
Create command button to print multiple worksheets in a excel file MarcoR Excel Discussion (Misc queries) 3 June 26th 06 07:07 PM
command button in excel will move when print. [email protected] Excel Discussion (Misc queries) 1 December 29th 04 03:53 PM


All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"