Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro from name stored in variable?


can you run a macro using its name stored in a variable?

e.g.:

======================
*mName = "Macro1"

Call mName *
========================

(I know the above doesn't work, but is there any similar method tha
does work?)

Many thanks

--
chubster26
-----------------------------------------------------------------------
chubster264's Profile: http://www.excelforum.com/member.php...fo&userid=3016
View this thread: http://www.excelforum.com/showthread.php?threadid=49846

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run macro from name stored in variable?

Use Application.Run.

Application.Run mName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"chubster264"
wrote
in message
...

can you run a macro using its name stored in a variable?

e.g.:

======================
*mName = "Macro1"

Call mName *
========================

(I know the above doesn't work, but is there any similar method
that
does work?)

Many thanks.


--
chubster264
------------------------------------------------------------------------
chubster264's Profile:
http://www.excelforum.com/member.php...o&userid=30164
View this thread:
http://www.excelforum.com/showthread...hreadid=498463



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro from name stored in variable?


Thanks for the suggestion - I'm getting an error 1004 though when I run
the code as below... Any further suggestions as to what might be the
problem?



Sub temp1()

MsgBox "hello"

End Sub

---------------------

Sub trythemacro()

Dim mName As String

mName = "temp1"

Application.Run (mName)

End Sub


--
chubster264
------------------------------------------------------------------------
chubster264's Profile: http://www.excelforum.com/member.php...o&userid=30164
View this thread: http://www.excelforum.com/showthread...hreadid=498463

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run macro from name stored in variable?

Your code works fine for me. Try removing the parentheses from
the Application.Run statement.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"chubster264"
wrote
in message
...

Thanks for the suggestion - I'm getting an error 1004 though
when I run
the code as below... Any further suggestions as to what might
be the
problem?



Sub temp1()

MsgBox "hello"

End Sub

---------------------

Sub trythemacro()

Dim mName As String

mName = "temp1"

Application.Run (mName)

End Sub


--
chubster264
------------------------------------------------------------------------
chubster264's Profile:
http://www.excelforum.com/member.php...o&userid=30164
View this thread:
http://www.excelforum.com/showthread...hreadid=498463



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run macro from name stored in variable?

I should have added that your called code must be in a regular
code module, not a sheet module, form module, or the ThisWorkbook
code module.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Your code works fine for me. Try removing the parentheses from
the Application.Run statement.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"chubster264"

wrote in message
...

Thanks for the suggestion - I'm getting an error 1004 though
when I run
the code as below... Any further suggestions as to what might
be the
problem?



Sub temp1()

MsgBox "hello"

End Sub

---------------------

Sub trythemacro()

Dim mName As String

mName = "temp1"

Application.Run (mName)

End Sub


--
chubster264
------------------------------------------------------------------------
chubster264's Profile:
http://www.excelforum.com/member.php...o&userid=30164
View this thread:
http://www.excelforum.com/showthread...hreadid=498463







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro from name stored in variable?


Chip,

Thanks so much! That nailed it.

:)

Chip Pearson Wrote:
I should have added that your called code must be in a regular
code module, not a sheet module, form module, or the ThisWorkbook
code module.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



--
chubster26
-----------------------------------------------------------------------
chubster264's Profile: http://www.excelforum.com/member.php...fo&userid=3016
View this thread: http://www.excelforum.com/showthread.php?threadid=49846

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hyperlink, macro, stored procedure? JICDB Excel Worksheet Functions 5 October 27th 07 12:18 AM
Run SQL Server stored procedure in Excel macro Peder Myhre Excel Programming 1 November 8th 05 10:54 PM
variable stored in Excel - read only from VBA Robert Mooney Excel Programming 3 June 22nd 04 02:49 AM
How to call a stored procedure in a macro Lee Dengo Excel Programming 2 May 12th 04 06:46 PM
Where is a macro shortcut key stored in a module? Christiane Excel Programming 3 April 2nd 04 04:47 AM


All times are GMT +1. The time now is 07:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"