Macro doesn't stop for button click

GA3

New Member
Joined
Nov 19, 2009
Messages
41
Office Version
  1. 365
  2. 2010
I have a formula that creates a button on my worksheet. I am calling the button macro from another macro. Everything works fine, and the button gets created, but the macro does not stop to wait for the button to get clicked. The button macro calls another macro and it rolls right into that one. I need the macro to stop so that the button can get clicked by the user, if desired. I am attaching the code. Please help me find my mistake. Thank you in advance.

Sub AddButtonAndCode()
' Declare variables
Dim i As Long, Hght As Long
Dim Name As String, NName As String
' Set the button properties
i = 0
Hght = 4.5
' Set the name for the button
NName = "cmdAction" & i
' Test if there is a button already and if so, increment its name
For Each OLEObject In ActiveSheet.OLEObjects
If Left(OLEObject.Name, 9) = "cmdAction" Then
Name = Right(OLEObject.Name, Len(OLEObject.Name) - 9)
If Name >= i Then
i = Name + 1
End If
NName = "cmdAction" & i
Hght = Hght + 27
End If
Next
' Add button
Dim myCmdObj As OLEObject, N%
Set myCmdObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=4.5, Top:=Hght, _
Width:=155.25, Height:=40.5)
' Define buttons name
myCmdObj.Name = NName
' Define buttons caption
myCmdObj.Object.Caption = "Click To Create" & vbNewLine & "Printable Bulletins"
Call Macro2


End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I don't think this code actually assigns any macro to run when your newbutton is clicked. What is happening is that macro2 is running, but it has nothing to do with the button. If you want Macro2 to run because the button is pushed, you have to assign macro2 to the button.

I searched around the internet and it appears difficult to assign code to a new button this way. But I like this idea:

Put a button the sheet manually, but set its visible property to false. Call macro2 in the button_click event. Then instead of the code you are using to add a button, just make an existing button visible. Would that work for your situation?
 
Upvote 0
I am open to anything. I just can not create the button until the previous macro finishes because the space I need the button to appear in is manipulated and not available until the very end of the macro.

All I really need is a button that I can create through code (or Macro) and assign a macro to that button that will run ONCE then be disabled when clicked, that says on 2 lines centered inthe button:
"Click To Create
Printable Bulletins"

Any help you can be would be greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top