Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to return an array to a macro sheet

Apologies to all, as this may be blindingly obvious, but I'm having problems
getting my head around Excel's arrays.

What I need to happen (in an XML macro on Excel 2003) is to delete several
(~100) worksheets.

Simple you (and Microsoft Excel Macro Functions Help) say use SET.NAME():
"If you need to return an array to a macro sheet (for example, if the macro
needs a list of all open windows), assign a name to the array instead of
placing the array information in a range of cells."

Then use WORKBOOK.DELETE():
"If you want to delete Sheet1:Sheet10, you must select them first with
WORKBOOK.SELECT(). You can also place the sheets in an array first, as in
{"Sheet1", "Sheet2", "Sheet3",...}."

My rather basic question is how do I place the sheets in an array without of
placing the array information in a range of cells and then assign a name to
this array worksheet names into an array?

The worksheet structure is typically:
1st worksheet: "Contents" - without "s of course
2nd: "(A Summary)"
3rd: "(All)"
4th to 4th from last: location based names, so don't follow any pattern
3rd from last: "z_Progress Breakdown"
2nd from last: "z_Summary"
last: "z_Upload Set"

many (anticipatory) thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to return an array to a macro sheet

Excle already has a collection - the worksheets object


Option Explicit
Sub DeleteSheets()
Dim shts() As Worksheet
Dim ws As Worksheet
Dim index As Long
ReDim shts(1 To Worksheets.Count)
For Each ws In Worksheets
index = index + 1
Set shts(index) = ws
Debug.Print ws.Name
Next

' do something with shts


End Sub



"Pico58" wrote:

Apologies to all, as this may be blindingly obvious, but I'm having problems
getting my head around Excel's arrays.

What I need to happen (in an XML macro on Excel 2003) is to delete several
(~100) worksheets.

Simple you (and Microsoft Excel Macro Functions Help) say use SET.NAME():
"If you need to return an array to a macro sheet (for example, if the macro
needs a list of all open windows), assign a name to the array instead of
placing the array information in a range of cells."

Then use WORKBOOK.DELETE():
"If you want to delete Sheet1:Sheet10, you must select them first with
WORKBOOK.SELECT(). You can also place the sheets in an array first, as in
{"Sheet1", "Sheet2", "Sheet3",...}."

My rather basic question is how do I place the sheets in an array without of
placing the array information in a range of cells and then assign a name to
this array worksheet names into an array?

The worksheet structure is typically:
1st worksheet: "Contents" - without "s of course
2nd: "(A Summary)"
3rd: "(All)"
4th to 4th from last: location based names, so don't follow any pattern
3rd from last: "z_Progress Breakdown"
2nd from last: "z_Summary"
last: "z_Upload Set"

many (anticipatory) thanks

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to return an array to a macro sheet

Many thanks Patrick,

Unfortunately I need to code this in XML/Macro 4.0.
I could call the VBA routine, but I'm pants at VBA and our IT security suites
seem to get upset when I do so!

Patrick Molloy wrote:
Excle already has a collection - the worksheets object

Option Explicit
Sub DeleteSheets()
Dim shts() As Worksheet
Dim ws As Worksheet
Dim index As Long
ReDim shts(1 To Worksheets.Count)
For Each ws In Worksheets
index = index + 1
Set shts(index) = ws
Debug.Print ws.Name
Next

' do something with shts

End Sub

Apologies to all, as this may be blindingly obvious, but I'm having problems
getting my head around Excel's arrays.

[quoted text clipped - 28 lines]

.


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
Macro formula array return limits? twaddell Excel Programming 4 August 12th 09 10:00 AM
How can I indicate in a macro to which last sheet to return ? Ron092007 Excel Programming 9 March 30th 09 05:00 AM
Macro to return to Current Sheet and Cell Steve Klenner Excel Programming 2 September 28th 05 02:38 PM
Return to Current Sheet in On (sheet activate) event macro Paul Moles Excel Programming 1 March 27th 05 03:16 PM
Return an array of all page ranges in a sheet? slovical Excel Programming 1 February 4th 04 09:07 PM


All times are GMT +1. The time now is 03:07 PM.

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"