G
Gregory Kip
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, Before:=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.
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, Before:=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.