Run application in 2nd workbook

  • Thread starter Thread starter Alan
  • Start date Start date
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
 
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)
 
Back
Top