Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed to solve printing error


I have the following code set up to print varying numbers of exce
workbooks, based on info from a master list, and it works fine, excep
for one thing. Whenever it comes across an item which requires 0 (zero
prints, it returns an error saying the number must be between 1 an
63212 (or something).

Any ideas on how I can get the macro to skip items which don't requir
printing?

Sub Printitem()

Dim a As String
Dim b As Integer
Dim c As Integer


'go down the list getting the name of the workbook and
'the amount needed

For b = 2 To Worksheets("Sheet1").Cells(65536, 1).End(xlUp).Row

'a gets the name of the workbook
a = Worksheets("Sheet1").Cells(b, 1).Value

'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook

Workbooks.Open ThisWorkbook.Path & Application.PathSeparator & a
".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False

'loop till end

Next b

End Su

--
madblok
-----------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...fo&userid=1442
View this thread: http://www.excelforum.com/showthread.php?threadid=39378

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Help needed to solve printing error

what about that:

'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook


if c < 0 then

Workbooks.Open ThisWorkbook.Path & Application.PathSeparator & a &
".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False


else

ActiveWorkbook.Close False

end if


'loop till end

Next b

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed to solve printing error


Thanks for that, but unfortunately doesnt work. Using your amendments,
if it hits a 0, it closes the master sheet.

I amended it so that it opened the unneeded sheet and then closed it
without printing, which worked, but took a long time (there's about 500
sheets to go through!)

What I need it to do ideally is ignore any unneeded sheets and just
open and print the ones I do need.

Snake Plissken Wrote:
what about that:

'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook


if c < 0 then

Workbooks.Open ThisWorkbook.Path & Application.PathSeparator & a &
".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False


else

ActiveWorkbook.Close False

end if


'loop till end

Next b

End Sub




--
madbloke
------------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...o&userid=14422
View this thread: http://www.excelforum.com/showthread...hreadid=393788

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Help needed to solve printing error


'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook


if c < 0 then

Workbooks.Open ThisWorkbook.Path & Application.PathSeparator & a &
".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False


' right - so it looks that <else command and next line is not required...


end if


'loop till end

Next b

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help needed to solve printing error

Option Explicit
Sub Printitem()

Dim a As String
Dim b As Long
Dim c As Long

'go down the list getting the name of the workbook and
'the amount needed

For b = 2 To Worksheets("Sheet1").Cells(65536, 1).End(xlUp).Row

'a gets the name of the workbook
a = Worksheets("Sheet1").Cells(b, 1).Value

'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook
If c 0 Then
Workbooks.Open ThisWorkbook.Path _
& Application.PathSeparator & a & ".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False
End If
'loop till end
Next b

End Sub

(Just making it easier to read.)


madbloke wrote:

I have the following code set up to print varying numbers of excel
workbooks, based on info from a master list, and it works fine, except
for one thing. Whenever it comes across an item which requires 0 (zero)
prints, it returns an error saying the number must be between 1 and
63212 (or something).

Any ideas on how I can get the macro to skip items which don't require
printing?

Sub Printitem()

Dim a As String
Dim b As Integer
Dim c As Integer

'go down the list getting the name of the workbook and
'the amount needed

For b = 2 To Worksheets("Sheet1").Cells(65536, 1).End(xlUp).Row

'a gets the name of the workbook
a = Worksheets("Sheet1").Cells(b, 1).Value

'c gets the number of prints needed
c = Worksheets("Sheet1").Cells(b, 8).Value

'print needed amount of workbook

Workbooks.Open ThisWorkbook.Path & Application.PathSeparator & a &
".xls"
ActiveSheet.PrintOut Copies:=c
ActiveWorkbook.Close False

'loop till end

Next b

End Sub

--
madbloke
------------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...o&userid=14422
View this thread: http://www.excelforum.com/showthread...hreadid=393788


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed to solve printing error


Spot on! Cheers.

I'd fallen into the trap of assuming an IF needed an ELSE

--
madblok
-----------------------------------------------------------------------
madbloke's Profile: http://www.excelforum.com/member.php...fo&userid=1442
View this thread: http://www.excelforum.com/showthread.php?threadid=39378

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
How to solve Error 2023 for Excel? Eric Excel Worksheet Functions 0 July 1st 07 02:24 PM
How do I solve the error this #VALUE! error James Rufus Excel Worksheet Functions 2 April 27th 06 04:25 PM
how do i solve 'file not found' error when linking notebooks? bmorar Excel Worksheet Functions 1 July 11th 05 10:40 PM
How do solve window explorer error c\Doc~1\admin~1\local~1\temp\wer8c2f.dr0 Excel Programming 1 December 22nd 04 05:41 PM
How do I solve Error 2902 Farneholm Excel Programming 0 November 16th 04 11:49 AM


All times are GMT +1. The time now is 09:06 AM.

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

About Us

"It's about Microsoft Excel"