ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assign Macro To Button At Runtime (https://www.excelbanter.com/excel-programming/317660-assign-macro-button-runtime.html)

swami

Assign Macro To Button At Runtime
 
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



Harald Staff

Assign Macro To Button At Runtime
 
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

"swami" skrev i melding
...
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





Rob van Gelder[_4_]

Assign Macro To Button At Runtime
 

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

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"swami" wrote in message
...
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






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

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