Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Selecting mulitple worksheets to Print (using VBA)

I need to select a user defined list of worksheets all at once using VBA.

I have a string variable containing a list of selected worksheets.
for example: mystring = "Sheet1,"&"Sheet2,"&"Sheet3"

Is it possible to pass the variable mystring as an argument in the following
function:
Sheets(Array(mystring)).Select without it generating an error message ?

Or is there another way of selecting worksheets at once using VBA ?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Selecting mulitple worksheets to Print (using VBA)

try one of these

Sub printsheets()
myarray = Array("sheet1", "sheet3")
For Each sh In Sheets(myarray)
sh.PrintPreview
Next
End Sub
Sub ps()
Sheets(Array("sheet1", "sheet3")).PrintPreview
End Sub


--
Don Guillett
SalesAid Software

"Adele" wrote in message
...
I need to select a user defined list of worksheets all at once using VBA.

I have a string variable containing a list of selected worksheets.
for example: mystring = "Sheet1,"&"Sheet2,"&"Sheet3"

Is it possible to pass the variable mystring as an argument in the

following
function:
Sheets(Array(mystring)).Select without it generating an error message ?

Or is there another way of selecting worksheets at once using VBA ?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting mulitple worksheets to Print (using VBA)

No. Instead of concatenating the sheet names, you need to put them into an
array. If you show the code where you build your string, perhaps it can be
modified to build an array.


This is a kludgy workarouand, but it will be limited in the number of sheet
names you can handle and is not recommended. Better to build the array the
right way.

Sub Testme()
myString = """Sheet1""," & """Sheet2""," & """Sheet3"""
myString = "{" & myString & "}"
varr = Evaluate(myString)
Worksheets(varr).Select
End Sub

--
Regards,
Tom Ogilvy


"Adele" wrote in message
...
I need to select a user defined list of worksheets all at once using VBA.

I have a string variable containing a list of selected worksheets.
for example: mystring = "Sheet1,"&"Sheet2,"&"Sheet3"

Is it possible to pass the variable mystring as an argument in the

following
function:
Sheets(Array(mystring)).Select without it generating an error message ?

Or is there another way of selecting worksheets at once using VBA ?



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
Cannot print both-sided by selecting multiple worksheets Queenie Chong Excel Discussion (Misc queries) 0 December 15th 09 03:54 AM
Counting values in mulitple worksheets Joan Excel Discussion (Misc queries) 2 July 4th 08 04:02 AM
How do I sum totals from mulitple worksheets unwizzed Excel Worksheet Functions 1 April 19th 06 10:43 PM
mulitple worksheets vlookup Max_power Excel Discussion (Misc queries) 7 March 21st 06 04:06 PM
Changes to Mulitple Worksheets Mac Landers Excel Worksheet Functions 3 January 26th 05 12:59 AM


All times are GMT +1. The time now is 05:35 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"