Thanks
Eradicator
No you can add a loop around the appropriate code that adds the menu item
which will have the sheet name.
for each sh in thisworkbook.Worksheets
with .Add . . .
.Caption = sh.name
.OnAction = "GoToSheet"
End with
Next
In gotosheet macro, you can use the ActiveControl.Caption to get the name
of the sheet to go to.
Regards,
Tom Ogilvy
"eradicator" <fh...@zlpbpx.gb> wrote in message
news:Oo_H5.2847$iY1....@sodalite.nbnet.nb.ca...
If you just want to be able to see a list of sheets and select from that
Right-Click on any of the sheet navigation buttons in lower left
corner. The sheetnames will not be sorted, but you can sort
the sheet tabs and then they will be same list, more information at.
http://www.geocities.com/davemcritchie/excel/excel.htm
HTH,
David McRitchie, Microsoft MVP - Excel (site changed 2000-04-15)
My Excel Macros: http://www.geocities.com/davemcritchie/excel/excel.htm
Sub CreateMenu()
Dim WB As Workbook
Dim WS As Worksheet
Const cTag = "__TempTag__"
With Application.CommandBars
If Not .FindControl(Tag:=cTag) Is Nothing Then
.FindControl(Tag:=cTag).Delete
End If
End With
With Application.CommandBars.ActiveMenuBar.Controls.Add( _
Type:=msoControlPopup, temporary:=True)
.Caption = "Sheets"
For Each WB In Workbooks
If WB.Windows(1).Visible = True Then
With .Controls.Add(Type:=msoControlPopup, _
temporary:=True)
.Caption = WB.Name
For Each WS In WB.Worksheets
With .Controls.Add
.Caption = WS.Name
.OnAction = "'" & ThisWorkbook.Name &
"'!ActivateSheet"
.Tag = WS.Range("A1").Address(True, True, xlA1,
True)
End With
Next WS
End With
End If
Next WB
End With
End Sub
Sub ActivateSheet()
Dim Rng As Range
Set Rng = Range(Application.CommandBars.ActionControl.Tag)
Rng.Parent.Parent.Activate
Rng.Parent.Select
End Sub
You'll have to re-run the macro when worksheets and/or workbooks are added,
deleted, or renamed.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"eradicator" <fh...@zlpbpx.gb> wrote in message
news:Oo_H5.2847$iY1....@sodalite.nbnet.nb.ca...
> Is there and easy way to take all current sheets and place them in a
custom
> menu in the command bar
>
> Thanks
>
> Eradicator
>
>
>
>
CHip your method is one I was looking for
You guys have saved me hours of programming difficulties
Thanks again
Eradicator
After the line
.Caption = "Sheets"
you need
.Tag = cTag
Otherwise, the menu won't get deleted before it is recreated.
> You guys have saved me hours of programming difficulties
We'll send you a bill.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"eradicator" <fh...@zlpbpx.gb> wrote in message
news:f30I5.2867$iY1....@sodalite.nbnet.nb.ca...
Just in case anyone wanted this
Eradicator
Thanks again everyone for your help
Sub CreateMenu()
Dim WB As Workbook
Dim WS As Worksheet
Const cTag = "__TempTag__"
With Application.CommandBars
If Not .FindControl(Tag:=cTag) Is Nothing Then
.FindControl(Tag:=cTag).Delete
End If
End With
With Application.CommandBars.ActiveMenuBar.Controls.Add( _
Type:=msoControlPopup, temporary:=True)
.Caption = "Sheets"
For Each WB In Workbooks
' If WB.Windows(1).Visible = True Then
' With .Controls.Add(Type:=msoControlPopup, _temporary:=True)
.Caption = WB.Name
For Each WS In WB.Worksheets
If WS.Visible = True Then
With .Controls.Add
.Caption = WS.Name
.OnAction = "'" & ThisWorkbook.Name &
"'!ActivateSheet"
.Tag = WS.Range("A1").Address(True, True, xlA1,
True)
End With
End If
Sub CreateSheetsMenu_ActivateSheet()
Dim Rng As Range
On Error Resume Next
Err.Number = 0
Set Rng = Range(Application.CommandBars.ActionControl.Tag)
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description & Chr(10) & _
"* 1004 The workbook is not open or does not match menu" & Chr(10) & _
"Rerun the CreateSheetsMenu with desired WorkBooks open"
CommandBars("Workbook tabs").ShowPopup 'Jim Rech posting
Exit Sub
End If
Rng.Parent.Parent.Activate
Rng.Parent.Select
End Sub
HTH,
David McRitchie, Microsoft MVP - Excel (site changed 2000-04-15)
My Excel Macros: http://www.geocities.com/davemcritchie/excel/excel.htm
Related Material: http://www.geocities.com/davemcritchie/excel/buildtoc.htm
Chip Pearson <ch...@cpearson.com> wrote in message
news:ukjxVQsOAHA.249@cppssbbsa05...