PC Review


Reply
Thread Tools Rate Thread

Can I pass control to a 2nd workbook

 
 
Alan
Guest
Posts: n/a
 
      13th Mar 2007
Apologies if this message is a near repeat of one I wrote earlier -
the earlier message woould appear to have been consigned to
hyperspace!

How can I, or indeed is it possible, to call a macro in a second
workbook and pass to it the value of a variable - in this case the
name of the 1st workbook?

The code that I have been trying to 'debunk' 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 line that is causing the problem: I am trying to run the
macro AnalyseResults(byval ThisWb as String) in the workbook Results
Analyser.xls ... can it be done? Is there a better way?

Thanks in anticipation ... even if the answer is bad news.

Alan

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      13th Mar 2007
think you just have a typo in your run command

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


should be

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

This assume the macro AnalyseResults is located in a general/standard module
named "Main" in the Results Analyser.xls workbook and it is declared to take
a string argument.

Public Sub AnalyseResults( s as String)

--
Regards,
Tom Ogilvy


"Alan" wrote:

> Apologies if this message is a near repeat of one I wrote earlier -
> the earlier message woould appear to have been consigned to
> hyperspace!
>
> How can I, or indeed is it possible, to call a macro in a second
> workbook and pass to it the value of a variable - in this case the
> name of the 1st workbook?
>
> The code that I have been trying to 'debunk' 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 line that is causing the problem: I am trying to run the
> macro AnalyseResults(byval ThisWb as String) in the workbook Results
> Analyser.xls ... can it be done? Is there a better way?
>
> Thanks in anticipation ... even if the answer is bad news.
>
> Alan
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Mar 2007
Check your other post, too.

Alan wrote:
>
> Apologies if this message is a near repeat of one I wrote earlier -
> the earlier message woould appear to have been consigned to
> hyperspace!
>
> How can I, or indeed is it possible, to call a macro in a second
> workbook and pass to it the value of a variable - in this case the
> name of the 1st workbook?
>
> The code that I have been trying to 'debunk' 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 line that is causing the problem: I am trying to run the
> macro AnalyseResults(byval ThisWb as String) in the workbook Results
> Analyser.xls ... can it be done? Is there a better way?
>
> Thanks in anticipation ... even if the answer is bad news.
>
> Alan


--

Dave Peterson
 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      20th Mar 2007
Thanks guys. I had all but given up on the two messages that I had
posted: for whatever reason I couldn't see either of them on my
machine for the first 48 hours after posting!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass variable from one workbook to another calebjill Microsoft Excel Misc 2 28th Jan 2009 07:38 PM
Pass Workbook Name Into Another Workbook As A Variable Minitman Microsoft Excel Programming 4 11th Sep 2008 06:48 AM
Pass ActiveCell Value to my Add In Workbook RyanH Microsoft Excel Programming 1 3rd Sep 2008 09:36 AM
pass workbook name to sub Przemek Microsoft Excel Programming 1 11th Aug 2005 04:09 PM
Pass a form value from a user control to parent control - Event Order issues ab_j@flyingrobot.com Microsoft ASP .NET 0 29th Oct 2004 06:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 PM.