PDA

View Full Version : Solved: Creating a Button For A Workbook Macro



zoom38
02-12-2006, 06:21 PM
I'm trying to make a button on the workbook that will activate a macro. I tried using Excel help but I still cant figure it out. I want this button to go with the workbook so others may use it when I send them the file. When you press the button I want it to call "Main" which runs the code.
Public Sub Main()
Application.ScreenUpdating = False
Dim rngStart As Range
Set rngStart = Selection
Sheets("Tables").Activate
' Sheets("Tables").Select
First_Shift_Sort
Flex_Shift_Sort
Second_Shift_Sort
SD_Sort

With rngStart
.Parent.Activate
.Select
End With
Application.ScreenUpdating = True
End Sub


Thanks
Gary

geekgirlau
02-12-2006, 06:40 PM
If you display the "Forms" toolbar, there is a button to create a command button, which you draw onto the worksheet. Once you've set the size and position of the button, it will prompt you for the name of the macro you want to link to.

zoom38
02-12-2006, 07:13 PM
Thank you geekgirl I was able to get it done your way.

Cyberdude
02-14-2006, 08:52 PM
Hey, geekgirlau, I tried out your suggestion (first time I've used the "Forms" toolbar), and the button is interesting, but perplexing. What kind of button is that? It doesn't seem to have the qualities of an AutoShape (which I prefer for buttons). http://vbaexpress.com/forum/images/smilies/102.gif