ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamically creating a toolbar button (https://www.excelbanter.com/excel-programming/355973-dynamically-creating-toolbar-button.html)

Gregory Kip[_2_]

Dynamically creating a toolbar button
 
Hello,

I am trying to create a toolbar button, paste an icon on it, and assign
it a macro -- all at run time.

Here is what I tried.
Insert-Picture-From File: ~/Desktop/whatever.bmp
Tools-Macro-Record New Macro: OK.
Selected the foo.bmp image with the mouse
Hit Ctrl-c to copy the image to the clipboard
On the toolbar, right-clicked, -Customize
In the Categories field, selected Macros
From the Commands field, dragged the Custom Button with smiley to the
toolbar
Selected the new button on the toolbar
Clicked Modify Selection
Changed the name to "&Show All Names"
Clicked Paste Button Image
Clicked Assign A Macro: Selected my Show_All_Names macro
Tools-Macro-Stop Recording


Here is the code it recorded, without comments:

Sub Macro1()
ActiveSheet.Shapes("Picture 1").Select
Selection.Copy
Application.CommandBars("Standard").Controls.Add Type:=msoControlButton,
ID _
:=2950, Befo=31
End Sub

If I run Macro1() again, a new button is created, but no macro is assigned,
and the button shows a smiley face, not whatever.bmp. Clearly those steps
weren't recorded. And though I've searched through the Object Browser, I
haven't found a way to do it.

Can anyone out there think of a way to do this? Can I programmatically
manipulate the drop-down menus? If I have to manipulate keystrokes, I will.

Thanks in advance,
Gregory Kip

Sorry about the false email address. I dislike spam. Please respond to the
newsgroup.




Gregory Kip[_2_]

Dynamically creating a toolbar button
 
That should be:
"Selected the whatever.bmp image with the mouse."




All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com