Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Worksheets and arrays

Given a variable that is a filename does anyone know how
to retrieve a list of all worksheets within that file and
place them in an array?

I eventually want the list to appear in a combo box so I
am assuming an array is the easiest way of doing this.

Any suggestions would be greatly appreciated

Nick
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Worksheets and arrays


"Nick" wrote in message
...
Given a variable that is a filename does anyone know how
to retrieve a list of all worksheets within that file and
place them in an array?

I eventually want the list to appear in a combo box so I
am assuming an array is the easiest way of doing this.


Not necessarily


Any suggestions would be greatly appreciated



This code should do the job nicely

Dim xlbook as Workbook , xlsheet as Worksheet

Set xlbook = xlapp.Workbooks.Open(wkbname)
For Each xlsheet in xlbook.Worksheets
myComboBox.Additem xlsheet.name
Next xlsheet

xlbook.Close

Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Worksheets and arrays

That seems perfect thank you - I'll try that now.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Worksheets and arrays

nice.
As a tip, its not always necessry to DIM an object to use
it. In this context, it probably is, since I'd imagine
using th ecombo to anable the user to manipulate whe
workbook.
However, if say you're working with the scripting
filesystemobject, then the following is quite useful.

Sub tester()
Dim wkbookname As String
Dim xlsheet As Worksheet

wkbookname = Application.GetOpenFilename()
With Workbooks.Open(wkbookname)
For Each xlsheet In .Worksheets
Debug.Print xlsheet.Name
Next xlsheet
.Close False
End With

End Sub

Note that th eworkbook object is implied in memory with
the WITH statement, and also that clean-up will occur
with the End With statement.

Hope that this may be of use in future

regards
PAtrick Molloy
Microsoft Excel MVP

-----Original Message-----

"Nick" wrote in

message
...
Given a variable that is a filename does anyone know

how
to retrieve a list of all worksheets within that file

and
place them in an array?

I eventually want the list to appear in a combo box so

I
am assuming an array is the easiest way of doing this.


Not necessarily


Any suggestions would be greatly appreciated



This code should do the job nicely

Dim xlbook as Workbook , xlsheet as Worksheet

Set xlbook = xlapp.Workbooks.Open(wkbname)
For Each xlsheet in xlbook.Worksheets
myComboBox.Additem xlsheet.name
Next xlsheet

xlbook.Close

Keith


.

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
Avg Arrays PAL Excel Worksheet Functions 2 February 13th 09 06:02 PM
Write a formula using two arrays, across two worksheets Susan Excel Worksheet Functions 11 July 29th 08 05:30 PM
Arrays Tobro88 Excel Discussion (Misc queries) 3 November 18th 05 11:28 PM
Arrays, & Worksheets & Grey Hair Peter Excel Discussion (Misc queries) 2 February 13th 05 01:35 AM
Arrays Colin Macleod Excel Programming 1 December 1st 03 04:32 PM


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