Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Custom Toolbar: ListBox on.action not working

I'm working with Excel 2003 and have written a macro for a floating
custom toolbar with a listbox. When I step through the macros to add
the commandbar and to use the listbox information they both work.
However when I "call" the macro using the .OnAction property a message
box is displayed saying the macro cannot be found. They are both
stored in the same module. Here are the macros...

Sub SelectSheetMenu()
Dim SheetSlct As CommandBar
Dim SelShtCtrl As CommandBarControl
Dim SheetNames As Range

Application.ScreenUpdating = False
Sheets("Lookups").Select
Range("A2").Select
Set SheetNames = Range(Cells(ActiveCell.Row, 1),
Cells(ActiveCell.End(xlDown).Row, 1))

'Delete existing toolbar if it exists
On Error Resume Next
CommandBars("Select Sheet").Delete
On Error GoTo 0

'Create new toolbar
Set SheetSlct = Application.CommandBars.Add("Select Sheet",
msoBarFloating, False, True)
SheetSlct.Visible = True

'Add dropdown control
Set SelShtCtrl = SheetSlct.Controls.Add(msoControlDropdown, 1, , ,
True)
SelShtCtrl.Visible = True

With SelShtCtrl
.Caption = "Select Worksheet"
.DescriptionText = "Go to a selected worksheet"
.Width = 150
.OnAction = "SelectSheet"
' fill it with SheetNames
For Each cell In SheetNames
.AddItem cell.Text
Next cell
.ListIndex = 2
End With

With SelShtCtrl
SlctdSht = .List(.ListIndex)
Sheets(SlctdSht).Select
End With

End Sub

Sub SelectSheet()
'Activates selected sheet
Dim SlctdSht As String
With CommandBars("Select Sheet").Controls("Select Worksheet")
SlctdSht = .List(.ListIndex)
Sheets(SlctdSht).Select
End With
End Sub

Can anyone determine where I'm going wrong?

Alison
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Custom Toolbar: ListBox on.action not working

Alison,

It worked for me in Excel 97.
However I had to declare two variables...
Dim Cell As Range
Dim SlctdSht As String

One thing you can try is to change...
.OnAction = "SelectSheet"
to
..OnAction = ThisWorkbook.Name & "!SelectSheet"

Regards,
Jim Cone
San Francisco, CA

"Alison" wrote in message om...
I'm working with Excel 2003 and have written a macro for a floating
custom toolbar with a listbox. When I step through the macros to add
the commandbar and to use the listbox information they both work.
However when I "call" the macro using the .OnAction property a message
box is displayed saying the macro cannot be found. They are both
stored in the same module. Here are the macros...

Sub SelectSheetMenu()
Dim SheetSlct As CommandBar
Dim SelShtCtrl As CommandBarControl
Dim SheetNames As Range
Application.ScreenUpdating = False
Sheets("Lookups").Select
Range("A2").Select
Set SheetNames = Range(Cells(ActiveCell.Row, 1),
Cells(ActiveCell.End(xlDown).Row, 1))
'Delete existing toolbar if it exists
On Error Resume Next
CommandBars("Select Sheet").Delete
On Error GoTo 0
'Create new toolbar
Set SheetSlct = Application.CommandBars.Add("Select Sheet",
msoBarFloating, False, True)
SheetSlct.Visible = True
'Add dropdown control
Set SelShtCtrl = SheetSlct.Controls.Add(msoControlDropdown, 1, , ,
True)
SelShtCtrl.Visible = True
With SelShtCtrl
.Caption = "Select Worksheet"
.DescriptionText = "Go to a selected worksheet"
.Width = 150
.OnAction = "SelectSheet"
' fill it with SheetNames
For Each cell In SheetNames
.AddItem cell.Text
Next cell
.ListIndex = 2
End With
With SelShtCtrl
SlctdSht = .List(.ListIndex)
Sheets(SlctdSht).Select
End With
End Sub

Sub SelectSheet()
'Activates selected sheet
Dim SlctdSht As String
With CommandBars("Select Sheet").Controls("Select Worksheet")
SlctdSht = .List(.ListIndex)
Sheets(SlctdSht).Select
End With
End Sub
Can anyone determine where I'm going wrong?
Alison

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Custom Toolbar: ListBox on.action not working


Hi Jim

Thanks for the advice. I've made your suggested changes but it still
can't find the called macro. I've tried it on a colleagues PC who is
using Excel 2000 and it doesn't work on hers either.

Very strange...

Thanks for the suggestions.

Alison

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Custom Toolbar: ListBox on.action not working

Alison,

Had another thought...
Your code should be in a "general" module - not in the sheet module or the workbook module?

Regards,
Jim Cone
San Francisco, CA

"Alison Rogers" wrote in message ...
Hi Jim
Thanks for the advice. I've made your suggested changes but it still
can't find the called macro. I've tried it on a colleagues PC who is
using Excel 2000 and it doesn't work on hers either.
Very strange...
Thanks for the suggestions.
Alison


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
Shift + toolbar button action in Excel 2007 Alojz Excel Discussion (Misc queries) 0 February 17th 09 08:41 PM
Custom toolbar for template - macros not working Ann Scharpf Excel Discussion (Misc queries) 2 February 5th 07 10:54 PM
custom toolbar buttons are saved where? Excel loads twice bymistake and all my custom toolbar buttons get gone!!! Kevin Waite Excel Programming 2 March 3rd 04 03:31 PM
Listbox on custom toolbar? Larry Adams Excel Programming 5 December 9th 03 08:52 AM


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