Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Code to print most (not all) pages within active workbook

I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code to print most (not all) pages within active workbook

Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Code to print most (not all) pages within active workbook

Sorry ... one other thing. One sheet not to print is called sheet1, but the other sheet not to print has the same name as the workbook name, how would I change "source data" to the workbook name?

Thanks Again,

Alan
"Ron de Bruin" wrote in message ...
Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code to print most (not all) pages within active workbook

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If lcase(sh.Name) = lcase(thisworkbook.name) Or lcase(sh.Name) = "sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub

You shouldn't need to replace 'Do nothing as it is a comment, not code.

Regards,
Tom Ogilvy


"AlanN" wrote in message ...
Sorry ... one other thing. One sheet not to print is called sheet1, but the other sheet not to print has the same name as the workbook name, how would I change "source data" to the workbook name?

Thanks Again,

Alan
"Ron de Bruin" wrote in message ...
Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Code to print most (not all) pages within active workbook

Alan,
try this

Sub Macro2()
Sheets(1).Activate
For i = 1 To Sheets.Count
Select Case Sheets(i).Name

Case Is = "Sheet1"

Case Is = "source data"

Case Else
Sheets(i).Activate
ActiveWindow.SelectedSheets.PrintPreview
End Select
Next i
End Sub

Cecil
"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code to print most (not all) pages within active workbook

See Tom's answer Alan

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I'm very green, sickly green, perhaps :(, with VBA.

I have tried this and nothing happens ... do I need to put something in place of " do nothing" ?

Thanks, Alan
"Ron de Bruin" wrote in message ...
Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Code to print most (not all) pages within active workbook

When I run this exact code in step mode, it skips from line 5 to 9 then 10,11 and finally 12.

There is no looping, it doesn't appear that it ever even looks to line 7 and 8. I have made sure that there are other pages not meeting the names I don't want printed.

Any ideas?

Thanks, Alan
"Tom Ogilvy" wrote in message ...
1Sub test()
2 Dim sh As Worksheet
3 Application.ScreenUpdating = False
4 For Each sh In ThisWorkbook.Worksheets
5 If lcase(sh.Name) = lcase(thisworkbook.name) Or lcase(sh.Name) = "sheet1" Then
6 ' Do Nothing
7 Else
8 sh.PrintOut
9 End If
10 Next
11 Application.ScreenUpdating = True
12 End Sub

You shouldn't need to replace 'Do nothing as it is a comment, not code.

Regards,
Tom Ogilvy


"AlanN" wrote in message ...
Sorry ... one other thing. One sheet not to print is called sheet1, but the other sheet not to print has the same name as the workbook name, how would I change "source data" to the workbook name?

Thanks Again,

Alan
"Ron de Bruin" wrote in message ...
Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message ...
I have a project where the resultant page tabs are variable in number and the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code to print most (not all) pages within active workbook

It only looks at worksheets.

I ran this on a 4 sheet workbook:

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If LCase(sh.Name) = LCase(ThisWorkbook.Name) _
Or LCase(sh.Name) = "sheet1" Then
' Do Nothing
Debug.Print "Not Printing: " & sh.Name
Else
Debug.Print "Printing: " & sh.Name
' sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub


and it produced:

Not Printing: Sheet1
Printing: sheet4
Printing: Sheet2
Not Printing: Book2
Printing: Sheet3


Regards,
Tom Ogilvy

"AlanN" wrote in message
...
When I run this exact code in step mode, it skips from line 5 to 9 then
10,11 and finally 12.

There is no looping, it doesn't appear that it ever even looks to line 7 and
8. I have made sure that there are other pages not meeting the names I don't
want printed.

Any ideas?

Thanks, Alan
"Tom Ogilvy" wrote in message
...
1Sub test()
2 Dim sh As Worksheet
3 Application.ScreenUpdating = False
4 For Each sh In ThisWorkbook.Worksheets
5 If lcase(sh.Name) = lcase(thisworkbook.name) Or lcase(sh.Name) =
"sheet1" Then
6 ' Do Nothing
7 Else
8 sh.PrintOut
9 End If
10 Next
11 Application.ScreenUpdating = True
12 End Sub

You shouldn't need to replace 'Do nothing as it is a comment, not code.

Regards,
Tom Ogilvy


"AlanN" wrote in message
...
Sorry ... one other thing. One sheet not to print is called sheet1, but the
other sheet not to print has the same name as the workbook name, how would I
change "source data" to the workbook name?

Thanks Again,

Alan
"Ron de Bruin" wrote in message
...
Try something like this

Sub test()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Name = "source data" Or sh.Name = "Sheet1" Then
' Do Nothing
Else
sh.PrintOut
End If
Next
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"AlanN" wrote in message
...
I have a project where the resultant page tabs are variable in number and
the sheet names change everytime it's run.

Can someone suggest any code that will print all the pages in the active
workbook except the pages called "Sheet1" and "source data"?

Thanks, Alan N


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
Can't print 3 pages of a workbook,it will only print one PeterM Excel Discussion (Misc queries) 2 July 23rd 07 07:18 PM
Code to Print Pages [email protected] Excel Discussion (Misc queries) 1 May 3rd 07 03:37 PM
Should all pages in a workbook print in color? Billy Excel Discussion (Misc queries) 1 March 21st 06 08:51 AM
How do I set my workbook up to print only first 2 pages? Bella Excel Discussion (Misc queries) 1 February 28th 06 06:38 PM
HOW DO I PRINT ALL PAGES AT ONCE IN A WORKBOOK THAT HAS ABOUT 20 . HASZIE Excel Discussion (Misc queries) 1 April 13th 05 05:44 PM


All times are GMT +1. The time now is 07:27 AM.

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"