PC Review


Reply
Thread Tools Rate Thread

Code modification please

 
 
=?Utf-8?B?VG9t?=
Guest
Posts: n/a
 
      27th Apr 2007
Hi all,
I use the following code to print all visible worksheets. Can it be modified
to NOT print a worksheet which is called "Main"?

thanks!

Sub Print_Visible_Worksheets()
'PRINT
'xlSheetVisible = -1
Dim sh As Worksheet
Dim arr() As String
Dim N As Integer
N = 0
For Each sh In ThisWorkbook.Worksheets
If sh.Visible = -1 Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = sh.Name
End If
Next
With ThisWorkbook
.Worksheets(arr).PrintOut
.Worksheets(1).Select
End With
End Sub
 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      27th Apr 2007
Hi Tom,

Try something like:

'=============>>
Public Sub Print_Visible_Worksheets()
Dim sh As Worksheet
Dim arr() As String
Dim N As Long
Const sStr As String = "Main" '<<=== CHANGE

For Each sh In ThisWorkbook.Worksheets
With sh
If .Visible = xlSheetVisible Then
If StrComp(.Name, sStr, vbTextCompare) Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = .Name
End If
End If
End With
Next sh

With ThisWorkbook
.Worksheets(arr).PrintPreview 'PrintOut
.Worksheets(1).Select
End With
End Sub
'<<=============


---
Regards,
Norman


"Tom" <(E-Mail Removed)> wrote in message
news:CCE36462-92C2-47BD-BCC3-(E-Mail Removed)...
> Hi all,
> I use the following code to print all visible worksheets. Can it be
> modified
> to NOT print a worksheet which is called "Main"?
>
> thanks!
>
> Sub Print_Visible_Worksheets()
> 'PRINT
> 'xlSheetVisible = -1
> Dim sh As Worksheet
> Dim arr() As String
> Dim N As Integer
> N = 0
> For Each sh In ThisWorkbook.Worksheets
> If sh.Visible = -1 Then
> N = N + 1
> ReDim Preserve arr(1 To N)
> arr(N) = sh.Name
> End If
> Next
> With ThisWorkbook
> .Worksheets(arr).PrintOut
> .Worksheets(1).Select
> End With
> End Sub



 
Reply With Quote
 
=?Utf-8?B?VG9t?=
Guest
Posts: n/a
 
      27th Apr 2007
Works like a charm!
Thanks Norman!

"Norman Jones" wrote:

> Hi Tom,
>
> Try something like:
>
> '=============>>
> Public Sub Print_Visible_Worksheets()
> Dim sh As Worksheet
> Dim arr() As String
> Dim N As Long
> Const sStr As String = "Main" '<<=== CHANGE
>
> For Each sh In ThisWorkbook.Worksheets
> With sh
> If .Visible = xlSheetVisible Then
> If StrComp(.Name, sStr, vbTextCompare) Then
> N = N + 1
> ReDim Preserve arr(1 To N)
> arr(N) = .Name
> End If
> End If
> End With
> Next sh
>
> With ThisWorkbook
> .Worksheets(arr).PrintPreview 'PrintOut
> .Worksheets(1).Select
> End With
> End Sub
> '<<=============
>
>
> ---
> Regards,
> Norman
>
>
> "Tom" <(E-Mail Removed)> wrote in message
> news:CCE36462-92C2-47BD-BCC3-(E-Mail Removed)...
> > Hi all,
> > I use the following code to print all visible worksheets. Can it be
> > modified
> > to NOT print a worksheet which is called "Main"?
> >
> > thanks!
> >
> > Sub Print_Visible_Worksheets()
> > 'PRINT
> > 'xlSheetVisible = -1
> > Dim sh As Worksheet
> > Dim arr() As String
> > Dim N As Integer
> > N = 0
> > For Each sh In ThisWorkbook.Worksheets
> > If sh.Visible = -1 Then
> > N = N + 1
> > ReDim Preserve arr(1 To N)
> > arr(N) = sh.Name
> > End If
> > Next
> > With ThisWorkbook
> > .Worksheets(arr).PrintOut
> > .Worksheets(1).Select
> > End With
> > End Sub

>
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      27th Apr 2007
Why not just

Sub printsheets()
For Each ws In Worksheets
If ws.Name <> "Main" And ws.Visible Then ws.PrintOut
Next ws
End Sub

Don Guillett
SalesAid Software
(E-Mail Removed)
"Tom" <(E-Mail Removed)> wrote in message
news:CCE36462-92C2-47BD-BCC3-(E-Mail Removed)...
> Hi all,
> I use the following code to print all visible worksheets. Can it be
> modified
> to NOT print a worksheet which is called "Main"?
>
> thanks!
>
> Sub Print_Visible_Worksheets()
> 'PRINT
> 'xlSheetVisible = -1
> Dim sh As Worksheet
> Dim arr() As String
> Dim N As Integer
> N = 0
> For Each sh In ThisWorkbook.Worksheets
> If sh.Visible = -1 Then
> N = N + 1
> ReDim Preserve arr(1 To N)
> arr(N) = sh.Name
> End If
> Next
> With ThisWorkbook
> .Worksheets(arr).PrintOut
> .Worksheets(1).Select
> End With
> End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
modification to this code James Microsoft Excel Misc 0 23rd Mar 2009 09:20 PM
Code modification? =?Utf-8?B?ZnBkODMz?= Microsoft Excel Programming 2 21st Sep 2007 04:52 PM
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram Microsoft Excel Programming 4 26th Sep 2006 04:15 AM
Code Modification =?Utf-8?B?U2t5IFdhcnJlbg==?= Microsoft Access Form Coding 1 17th Mar 2005 07:48 PM
Code modification Mas Microsoft Excel Programming 3 29th Mar 2004 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 AM.