Run application in 2nd workbook

A

Alan

Is it possible pass control to a macro in a second workbook that
requires the value of a variable from the first?

The code I have so far is:

Sub CallResultsAnalyser()

Dim ThisWb As String
Dim ResAnalysis As String

ThisWb = ActiveWorkbook.Name
ResAnalysis = "p:\results analyser.xls"

' Open the results analyser if it isn't already open
On Error Resume Next
Application.Workbooks.Open (ResAnalysis)
On Error GoTo 0

Application.Run ("'Results Analyser.xls'Main!AnalyseResults",ThisWb)

End Sub

It's the last statement I am having problems with - the aim is to run
AnalyseResults(ThisWb) in the workbook Results Analyser.xls ... can it
be done?

Thanks in advance (even if it is bad news!)

Alan
 
D

Dave Peterson

Instead of this:

Application.Run ("'Results Analyser.xls'Main!AnalyseResults",ThisWb)

It should look more like:

Application.Run "'Results Analyser.xls'!Main.AnalyseResults", ThisWb

(assuming Main is the module name in the "results analyser.xls" project that
holds the procedure analyseresults.)

If you wanted to bring back some value (if analyseresults is a function):

dim res as variant 'whatever you bring back
res = Application.Run("'Results Analyser.xls'!Main.AnalyseResults", ThisWb)
 

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

Top