Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

Hi

Is it possible to read either the module and/or the sub name and use it as a
string within the code?

R
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Module / Sub as string

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

Ho Hum, is the only polite answer I have

Thanks anyway thought I was going barmy

"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Module / Sub as string

A very useful tip.
--
Gary''s Student - gsnu200791


"Richard" wrote:

Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

can you recommend a book which will help me learn how to use the vba interface.
I am (very) slowly getting my head around the vba concepts, but feel that
knowing how to use the object explorer, debug tools etc would reduce the
amount so questions I have to ask.

I guess this is an issue for lots of (so called) self taught coders.

"Gary''s Student" wrote:

A very useful tip.
--
Gary''s Student - gsnu200791


"Richard" wrote:

Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Module / Sub as string

There are many good books. I use:

Walkenbach's Excel 2003 Power Programming with VBA
Frye, Freeze, Buckingham's Excel2003 Programming
and
Bullen, Bovey, Green's Professional Excel Development

There are also many good on-line resources.
--
Gary''s Student - gsnu200791


"Richard" wrote:

can you recommend a book which will help me learn how to use the vba interface.
I am (very) slowly getting my head around the vba concepts, but feel that
knowing how to use the object explorer, debug tools etc would reduce the
amount so questions I have to ask.

I guess this is an issue for lots of (so called) self taught coders.

"Gary''s Student" wrote:

A very useful tip.
--
Gary''s Student - gsnu200791


"Richard" wrote:

Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

thanks for the tips.

I have found a problem with my suggestion, in that you need to make the
module for the sub you are running, the active module, otherwise you get bad
results. If you can cure this, then it becomes a useable suggestion

"Gary''s Student" wrote:

There are many good books. I use:

Walkenbach's Excel 2003 Power Programming with VBA
Frye, Freeze, Buckingham's Excel2003 Programming
and
Bullen, Bovey, Green's Professional Excel Development

There are also many good on-line resources.
--
Gary''s Student - gsnu200791


"Richard" wrote:

can you recommend a book which will help me learn how to use the vba interface.
I am (very) slowly getting my head around the vba concepts, but feel that
knowing how to use the object explorer, debug tools etc would reduce the
amount so questions I have to ask.

I guess this is an issue for lots of (so called) self taught coders.

"Gary''s Student" wrote:

A very useful tip.
--
Gary''s Student - gsnu200791


"Richard" wrote:

Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it as
a
string within the code?

R



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Module / Sub as string

Hi Richard

I've ran code like this

Sub test3()
ClientName = Application.VBE.ActiveCodePane.CodeModule.Name
MsgBox ClientName
End Sub

placed in three different modules. They all returned "Module3", not the
module containing the running code. Am I missing something ?

Best wishes Harald

"Richard" skrev i melding
...
Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows
me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub
for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it
as
a
string within the code?

R






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Module / Sub as string

no that is the point I made, if the last module you updated was module 3 that
module seems to retain the active setting. I don't know how to set the
module for the sub you are running, as the active code window, or perhaps
some other method needs to be found

"Harald Staff" wrote:

Hi Richard

I've ran code like this

Sub test3()
ClientName = Application.VBE.ActiveCodePane.CodeModule.Name
MsgBox ClientName
End Sub

placed in three different modules. They all returned "Module3", not the
module containing the running code. Am I missing something ?

Best wishes Harald

"Richard" skrev i melding
...
Harald

I got it,

Dim ClientName As String

ClientName = Application.VBE.ActiveCodePane.CodeModule.Name

This enables me to give each module the client name, which in turn allows
me
to use the ClientName string as part of the file path. No need to search
through and make code changes for each new client and the sub name can be
whatever I like, which is handy as in some cases I have more than 1 sub
for
the same client.

Richard


"Harald Staff" wrote:

Hi R

Afaik no, sorry. It would make error handling far easier if it was.

Best wishes Harald


"Richard" skrev i melding
...
Hi

Is it possible to read either the module and/or the sub name and use it
as
a
string within the code?

R






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
Compile Error in Hidden Module: Module 1 Mim Excel Programming 3 January 23rd 10 12:22 AM
Add a VBA Module from a String instead of from a file [email protected][_2_] Excel Programming 1 February 26th 08 06:35 PM
Use String from another module Silencer116 Excel Programming 1 June 16th 06 01:52 PM
Excel VBA to search all macro code in Excel module for specific string criteria Roger1947 Excel Programming 0 May 19th 04 05:51 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 03:59 PM.

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"