Assign Macro To Button At Runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ,

I am creating a button thru macro and assign a function named Refresh.
It is executing well. While opening the workbook, there is an error pops up
"Macro name is not valid, check the name"

But macro is executing . IS there any way to find out what is the problem

My macro is in Module1 .

Sub refresh

end sub
OR
function refresh
End function
which is correct

but for both having issue
 
Hi

You don't share the creation/assignment code, but try assigning to

ThisWorkbook.Name & "!Refresh"

and see if it helps.

HTH. best wishes Harald
 
If you have a button created by the Forms toolbox, then you can assign the
macro at runtime as this example demonstrates:

Sub test()
ActiveSheet.Shapes("Button 1").OnAction = ThisWorkbook.Name & "!Refresh"
End Sub

Public Function Refresh()
MsgBox "Hello World"
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top