PC Review


Reply
Thread Tools Rate Thread

Create generic macro for a custom toolbar

 
 
spIky haIred
Guest
Posts: n/a
 
      29th Oct 2007
Hi all,

How do I pick up the name of a custom toolbar item when it is clicked?
I would like to use it the toolbar for navigation purposes in a
similar way I would if it was called from a button, e.g.

Public Sub GoToSheet()
Worksheets(Application.Caller).Activate
End Sub

If I use this behind a button on a toolbar it will fail.. is there
another way to do it?

Thanks.

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      29th Oct 2007

Application.CommandBars.ActionControl
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"spIky haIred"
wrote in message
Hi all,
How do I pick up the name of a custom toolbar item when it is clicked?
I would like to use it the toolbar for navigation purposes in a
similar way I would if it was called from a button, e.g.

Public Sub GoToSheet()
Worksheets(Application.Caller).Activate
End Sub

If I use this behind a button on a toolbar it will fail.. is there
another way to do it?
Thanks.

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      29th Oct 2007
Hi Jim,

I got a run time error 438 - object does not support property/
method... strange... any idea what i might be doing wrong? i assigned
a macro to a button on the toolbar. The macro was just a simple one
like so:

Public Sub Test
Msgbox Application.CommandBars.ActionControl
End sub

Thanks.

 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      29th Oct 2007
Actually, I got it now. Thanks for your help. I used: MsgBox
CommandBars.ActionControl.Tag

 
Reply With Quote
 
Bill Renaud
Guest
Posts: n/a
 
      29th Oct 2007
Try the following routine:

Public Sub Test()
Dim varCaller As Variant
Dim strToolbarName As String
Dim lngControlNumber As Long

varCaller = Application.Caller

If VarType(varCaller) = vbArray + vbVariant _
Then
lngControlNumber = varCaller(1)
strToolbarName = varCaller(2)
End If
End Sub

The best thing I can suggest is to single-step through this code and use
the Locals window to inspect the value of varCaller right after the line
that fetches its value from Application.Caller.

For a more general-purpose routine, you might want to use a Select Case
statement, instead of the If statement that I used for this simple case.
For robust code, you need to use VarType to check to see what type of
Variant was returned from Application.Caller. It will be all different
types, depending on whether your routine was called from a worksheet cell,
a toolbar control, etc. In this case, it is an array of Variants (one
variant holds the Toolbar name and the other variant holds the index number
of the control that was clicked).

--
Regards,
Bill Renaud



 
Reply With Quote
 
spIky haIred
Guest
Posts: n/a
 
      30th Oct 2007
Much appreciated thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Isn't there a way to create your own custom toolbar buttons? Misdeerose Microsoft Word Document Management 1 6th Aug 2008 12:46 AM
Create macro to load custom toolbar Jose Ruben Gonzalez-Baird Microsoft Excel Programming 5 27th Dec 2007 11:12 PM
Create a custom toolbar =?Utf-8?B?UmhvbmRh?= Microsoft Outlook VBA Programming 6 30th Jan 2007 08:28 AM
How do I create a custom image for a toolbar? korrin.anderson@gmail.com Microsoft Excel Programming 2 7th Jul 2006 11:05 PM
How to create custom IE Toolbar Big Poppa Windows XP Internet Explorer 1 24th Nov 2003 06:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 PM.