Execute a sub in a different project

A

Antonio

How do I run a sub that is declared as public in a different open workbook
(project)?

Thanks,

Antonio
 
D

Dave Peterson

dim otherworkbook as workbook

set otherworkbook = workbooks("yourothernamehere.xls")

application.run "'" & otherworkbook.name & "'!macronamehere"
 
A

Antonio

I have used

I get:

Run-time error '1004':

The macro 'myworkbook.xls!kill_max_min' cannot be found.

In myworkbook I have

Public Sub kill_max_min()

Application.OnTime runwhen, "max_min", , False

End Sub


What am I doing wrong?

Thanks,

Antonio
 
D

Dave Peterson

What did you use?
I have used

I get:

Run-time error '1004':

The macro 'myworkbook.xls!kill_max_min' cannot be found.

In myworkbook I have

Public Sub kill_max_min()

Application.OnTime runwhen, "max_min", , False

End Sub

What am I doing wrong?

Thanks,

Antonio
 
A

Antonio

Sorry, I have used

Application.Run "myworkbook.xls!kill_max_min"

I have also tried


Dim otherworkbook As Workbook
Set otherworkbook = Workbooks("myworkbook.xls")
Application.Run "'" & otherworkbook.Name & "!kill_max_min"

The run method does seem to pint to myworkbook.xls but cannot find the sub
 
D

Dave Peterson

You dropped a single quote from this attempt:
Application.Run "'" & otherworkbook.Name & "'!kill_max_min"

But I don't think that's the problem.

Both versions (after correction) worked ok for me.

Is Kill_max_min in a general module?
 
C

Chip Pearson

Just to cover all the bases, is the workbook containing the macro
open? It must be.


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