Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Returning the name of a module

I have a collection of "utility" modules that I wish to be able to import
into a number of workbooks, and then run. Below is the code I wished to use
to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files", MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add",
MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named. The trouble I am
having is in retrieving the name of the module in order to run the macro in
it. The modules all contain one macro, named the same as the module name. For
instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath, "P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant - does
anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary and
those who don't.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default Returning the name of a module

hi, Geoff !

I would get the (*.bas) "clean" filename from the full-path returned by GetOpenFileName
- (i.e.) Dir(modName(j))

and then, "clear" the ".bas" EXTension from the filename
- len(... & instr(...
- replace(...
- other/s ?

hth,
hector.

__ OP __
I have a collection of "utility" modules that I wish to be able to import into a number of workbooks
and then run. Below is the code I wished to use to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files", MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add", MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named.
The trouble I am having is in retrieving the name of the module in order to run the macro in it.
The modules all contain one macro, named the same as the module name.
For instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath, "P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant
- does anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary and those who don't.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Returning the name of a module

As an aside, having a module and macro name the same has been shown to give
problems, not a good practice.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Geoff" wrote in message
...
I have a collection of "utility" modules that I wish to be able to import
into a number of workbooks, and then run. Below is the code I wished to
use
to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files",
MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add",
MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named. The trouble I
am
having is in retrieving the name of the module in order to run the macro
in
it. The modules all contain one macro, named the same as the module name.
For
instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath,
"P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant -
does
anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary
and
those who don't.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Returning the name of a module

.....and even bigger problems trying to track the arising problem down!!

(first hand experience - don't do it!)

HTH

--

Regards,
Nigel




"Bob Phillips" wrote in message
...
As an aside, having a module and macro name the same has been shown to
give problems, not a good practice.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Geoff" wrote in message
...
I have a collection of "utility" modules that I wish to be able to import
into a number of workbooks, and then run. Below is the code I wished to
use
to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files",
MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add",
MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named. The trouble I
am
having is in retrieving the name of the module in order to run the macro
in
it. The modules all contain one macro, named the same as the module name.
For
instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath,
"P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant -
does
anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary
and
those who don't.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Returning the name of a module

I have never named a module and a procedure the same (aren't I good <vbg),
but I have heard the anecdotes.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Nigel" wrote in message
...
....and even bigger problems trying to track the arising problem down!!

(first hand experience - don't do it!)

HTH

--

Regards,
Nigel




"Bob Phillips" wrote in message
...
As an aside, having a module and macro name the same has been shown to
give problems, not a good practice.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Geoff" wrote in message
...
I have a collection of "utility" modules that I wish to be able to import
into a number of workbooks, and then run. Below is the code I wished to
use
to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files",
MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add",
MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named. The trouble I
am
having is in retrieving the name of the module in order to run the macro
in
it. The modules all contain one macro, named the same as the module
name. For
instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath,
"P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant -
does
anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary
and
those who don't.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Returning the name of a module

;-) - I never do now!

All my module names a prefixed with 'm'



--

Regards,
Nigel




"Bob Phillips" wrote in message
...
I have never named a module and a procedure the same (aren't I good <vbg),
but I have heard the anecdotes.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Nigel" wrote in message
...
....and even bigger problems trying to track the arising problem down!!

(first hand experience - don't do it!)

HTH

--

Regards,
Nigel




"Bob Phillips" wrote in message
...
As an aside, having a module and macro name the same has been shown to
give problems, not a good practice.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Geoff" wrote in message
...
I have a collection of "utility" modules that I wish to be able to
import
into a number of workbooks, and then run. Below is the code I wished to
use
to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files",
MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add",
MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named. The trouble
I am
having is in retrieving the name of the module in order to run the
macro in
it. The modules all contain one macro, named the same as the module
name. For
instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath,
"P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant -
does
anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary
and
those who don't.






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Returning the name of a module

Hi Hector, muchas gracias - in the end I went with a combination of mid,
instrrev and len to get the clean filename as you suggested.
@Bob, Nigel - thanks guys, yes it's not great practice I know but I don't
intend to do it regularly. In fact having thought about it a quicker (or at
least easier) way to do this would have been to simply rewrite the utilities
to work on a supplied workbook variable rather than using ThisWorkbook.
However I am a little curious about the information available from a module
once it has been imported - for instance is it possible to access a list of
the macros contained within it? Or even to pick up the name of the module
itself? I guess this is the main motivation behind my post.

Thanks all.
--
There are 10 types of people in the world - those who understand binary and
those who don't.


"Héctor Miguel" wrote:

hi, Geoff !

I would get the (*.bas) "clean" filename from the full-path returned by GetOpenFileName
- (i.e.) Dir(modName(j))

and then, "clear" the ".bas" EXTension from the filename
- len(... & instr(...
- replace(...
- other/s ?

hth,
hector.

__ OP __
I have a collection of "utility" modules that I wish to be able to import into a number of workbooks
and then run. Below is the code I wished to use to do this:

Option Explicit

Sub Add_Modules()

Dim wbName
Dim wkBk As Workbook
Dim modName
Dim i As Integer
Dim j As Integer
Dim module As String

wbName = Application.GetOpenFilename(Title:="Select Files", MultiSelect:=True)
modName = Application.GetOpenFilename(Title:="Select Modules to Add", MultiSelect:=True)
For i = LBound(wbName) To UBound(wbName)
Set wkBk = Workbooks.Open(wbName(i))
For j = LBound(modName) To UBound(modName)
Call InsertVBComponent(wkBk, modName(j))
module = ? ' This is where I'm stuck...
Application.Run (wkBk.Name & "!" & module)
Next j
Next i

End Sub

InsertVBComponent is a sub which imports the module named.
The trouble I am having is in retrieving the name of the module in order to run the macro in it.
The modules all contain one macro, named the same as the module name.
For instance, Reset.bas is as follows:

Attribute VB_Name = "Reset"
Option Explicit

Sub Reset()

Dim linkArr
Dim i As Integer
Dim newLink As String
linkArr = ThisWorkbook.LinkSources
For i = 1 To UBound(linkArr)
newLink = Replace(linkArr(i), Application.StartupPath, "P:\CASE\MIPROJ")
ThisWorkbook.ChangeLink linkArr(i), newLink
Next i
End Sub

One approach I have considered taking is to use the VB_Name constant
- does anyone know how to retrieve this from the module?
--
There are 10 types of people in the world - those who understand binary and those who don't.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a value forom a Module to a Userform CSUS_CE_Student[_2_] Excel Programming 3 April 23rd 07 08:44 AM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Run worksheet module code from workbook module? keithb Excel Programming 1 August 14th 05 04:04 AM
Calls from sheet module to ThisWorkbook module quartz[_2_] Excel Programming 2 June 23rd 05 03:37 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 02:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"