ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OnAction macro in another wb (https://www.excelbanter.com/excel-programming/369180-onaction-macro-another-wb.html)

Desert Piranha[_96_]

OnAction macro in another wb
 

Hi all,

I put some command bar code into my Add-In, The OnAction is to call a
Macro Named "aTest".
The twist is that the macro is not physically in the Add-In. It is in
various workbooks,
but the macro name is always "aTest"

I'm trying to call the macro with a variable (active workbook) &
"aTest".

some stuff tried:
With .Add(temporary:=True)
..Caption = "aTest"
'.OnAction = ThisWorkbook.Name & "!aTest"
'.OnAction = "ActiveWorkbook.Name" & "!aTest"
'.OnAction = ActiveWorkbook & "!aTest"
'.OnAction = "ActiveWorkbook.Name & '!aTest'"
'.OnAction = "!aTest"
'.OnAction = ActiveWorkbook.Name & ".xls" & "!aTest"
'.OnAction = "aTest"
End With

All the other code works fine,
and if i put the code into the same workbook as the macro it works fine
with:
'.OnAction = ThisWorkbook.Name & "!aTest"


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=567643


Dave Peterson

OnAction macro in another wb
 
Untested.

Maybe have your .onaction point to a macro that's in ThisWorkbook.

..onaction = "'" & thisworkbook.name & "'!RunATest"

Then RunATest could do the real work based on the active workbook's name.

Option Explicit
sub RunATest()
application.run "'" & activeworkbook.name & "'!ATest"
end sub



Desert Piranha wrote:

Hi all,

I put some command bar code into my Add-In, The OnAction is to call a
Macro Named "aTest".
The twist is that the macro is not physically in the Add-In. It is in
various workbooks,
but the macro name is always "aTest"

I'm trying to call the macro with a variable (active workbook) &
"aTest".

some stuff tried:
With .Add(temporary:=True)
Caption = "aTest"
'.OnAction = ThisWorkbook.Name & "!aTest"
'.OnAction = "ActiveWorkbook.Name" & "!aTest"
'.OnAction = ActiveWorkbook & "!aTest"
'.OnAction = "ActiveWorkbook.Name & '!aTest'"
'.OnAction = "!aTest"
'.OnAction = ActiveWorkbook.Name & ".xls" & "!aTest"
'.OnAction = "aTest"
End With

All the other code works fine,
and if i put the code into the same workbook as the macro it works fine
with:
'.OnAction = ThisWorkbook.Name & "!aTest"

--
Desert Piranha

------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=567643


--

Dave Peterson

Desert Piranha[_97_]

OnAction macro in another wb
 

Dave Peterson Wrote:
Untested.

Maybe have your .onaction point to a macro that's in ThisWorkbook.

..onaction = "'" & thisworkbook.name & "'!RunATest"

Then RunATest could do the real work based on the active workbook's
name.

Option Explicit
sub RunATest()
application.run "'" & activeworkbook.name & "'!ATest"
end subHi Dave,


Very masterfull, works great. Thx Very much.


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=567643



All times are GMT +1. The time now is 09:16 PM.

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