PDA

View Full Version : Solved: Passing a module as a parameter



tools
01-12-2009, 03:00 AM
Hi All,

Is it possible to pass a module as a parameter to a function and use it ?
I have attached an excel sheet for the same.

Thanks & Regards

Bob Phillips
01-12-2009, 03:27 AM
Let's take a step back.

What are you trying to achieve?

tools
01-12-2009, 03:52 AM
I want to make a common module which would set some variables.
Now the variables that I am setting could have the same name in multiple modules.
I am trying to do this so that I could refer only the variable in the calling module.

Is there a better solution to this ?

Thanks & Regards

Bob Phillips
01-12-2009, 04:30 AM
I wouldn't use the same name variable in multipl modules. Without knowing the full detail, I wouldprobably create global arrays, and allocate each module a id number into the array.

tools
01-19-2009, 05:12 AM
Consider a case where I am calling web services through my excel add in.
I have 2 modules for 2 different web services.
Each has its own URL which has the same name in both modules.
While sending the data I will call a common function which would decide which URL to set depending on the calling module name.

Is this possible ?

Bob Phillips
01-19-2009, 07:05 AM
I can't say that I am getting it yet, but it seems overly complex to me. Why not assign a value to a variable, different depending upon the service.

Paul_Hossler
01-19-2009, 07:31 AM
In the attached WB there are 2 modules, each with a similarly named sub

The 'main' sub (drv) and it's called private sub might do what you want, at least as a starting point



Option Explicit
Sub drv()
Call CallModule("Module1", "CommonSub")
Call CallModule("Module2", "CommonSub")
Call CallModule("Module1", "CommonSub")

End Sub

Private Sub CallModule(M As String, S As String)
Application.Run (M & "." & S)

End Sub


Paul

tools
01-19-2009, 08:16 PM
Thanks Paul
This is what i wanted :)