ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   command button (https://www.excelbanter.com/excel-programming/318045-command-button.html)

tjh

command button
 
Hello,

Is it possible to use a macro to create a command button, which would run an
additional at the users request. Let me know if you need more info.

Thank You,

JE McGimpsey

command button
 
I'm not sure what you mean by "run an additional", but here's a macro
I've used to put a Forms command button (Forms) on the worksheet, and
open the assign macro dialog to allow the user to assign a macro, and
labels the button with the macro name.

Public Sub AddButtonToSheet()
'J.E. McGimpsey 2001-10-13
'Put Forms Command Button on sheet, Format it,
'and assign a macro to it.
Dim oOldSelection As Object
Dim rOldActive As Range
Dim sCaption As String
Set oOldSelection = Selection
If TypeName(oOldSelection) = "Range" Then _
Set rOldActive = ActiveCell
Application.ScreenUpdating = False
With ActiveSheet.Shapes.AddFormControl( _
xlButtonControl, 600, 50, 1, 23)
.ControlFormat.PrintObject = False
With .TextFrame.Characters.Font
.Name = "Verdana"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = 13
.Shadow = False
End With
.Select
Application.Dialogs(xlDialogAssignToObject).Show "try"
sCaption = .OnAction
If Len(sCaption) 0 Then _
Selection.Caption = Mid(sCaption, InStr(sCaption, "!") + 1)
Selection.AutoSize = True
End With
oOldSelection.Select
If Not rOldActive Is Nothing Then rOldActive.Activate
Application.ScreenUpdating = True
End Sub

In article ,
tjh wrote:

Hello,

Is it possible to use a macro to create a command button, which would run an
additional at the users request. Let me know if you need more info.

Thank You,


tjh

command button
 
Yes, this is exactly what I need. The only change is rather than allowing the
user to assign the macro to run, I would like to place the macro in the code.
So that if the user hits the button it will run the macro that I have
assigned. Having a little trouble with the change, where should I place this
code with in yours?:

ActiveSheet.Shapes("Button 1").Select
Selection.OnAction = "Macro1"



"JE McGimpsey" wrote:

I'm not sure what you mean by "run an additional", but here's a macro
I've used to put a Forms command button (Forms) on the worksheet, and
open the assign macro dialog to allow the user to assign a macro, and
labels the button with the macro name.

Public Sub AddButtonToSheet()
'J.E. McGimpsey 2001-10-13
'Put Forms Command Button on sheet, Format it,
'and assign a macro to it.
Dim oOldSelection As Object
Dim rOldActive As Range
Dim sCaption As String
Set oOldSelection = Selection
If TypeName(oOldSelection) = "Range" Then _
Set rOldActive = ActiveCell
Application.ScreenUpdating = False
With ActiveSheet.Shapes.AddFormControl( _
xlButtonControl, 600, 50, 1, 23)
.ControlFormat.PrintObject = False
With .TextFrame.Characters.Font
.Name = "Verdana"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = 13
.Shadow = False
End With
.Select
Application.Dialogs(xlDialogAssignToObject).Show "try"
sCaption = .OnAction
If Len(sCaption) 0 Then _
Selection.Caption = Mid(sCaption, InStr(sCaption, "!") + 1)
Selection.AutoSize = True
End With
oOldSelection.Select
If Not rOldActive Is Nothing Then rOldActive.Activate
Application.ScreenUpdating = True
End Sub

In article ,
tjh wrote:

Hello,

Is it possible to use a macro to create a command button, which would run an
additional at the users request. Let me know if you need more info.

Thank You,



tjh

command button
 
Got it, nevermind.

Thank You for your help!!!!!!





"tjh" wrote:

Hello,

Is it possible to use a macro to create a command button, which would run an
additional at the users request. Let me know if you need more info.

Thank You,



All times are GMT +1. The time now is 05:20 PM.

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