Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default common functions:where to put them?

I have written an Excel macro which is subdivided into 6 modules.

Although the functions in each are largely distinct, there are three
functions which 5 of the modules use in common. These are used for
reading data from/to names in a workbook (see bottom).

Since all are Private, I have had to make copies of them in each of the
5 modules that use them. Other than making them Public, how would the
group suggest I get away from this duplication?

The idea of a code module holding common functions appeals, but how
then can I call the functions from other modules?

Your guidance and suggestions invited ...

Thanks
MGD


Private Function addNameAndData(wkb As Workbook, wshIndex As Variant,
name As Variant, refersto As Variant, visible As Boolean)
'adds name to specified wkb and sheet, and stores data init
wkb.Sheets(wshIndex).Names.Add name:=name, refersto:=refersto,
visible:=visible
End Function

Private Function getNameData(wkb As Workbook, wshIndex As Variant, name
As Variant) As Variant
'recovers data from name specified
getNameData = wkb.Worksheets(wshIndex).Evaluate(name)
End Function

Private Function setNameData(wkb As Workbook, wshIndex As Variant, name
As Variant, refersto As Variant, visible As Boolean)
'identical to addNameAndData, but conceptually distinct in that is used
to update info in an extant name
wkb.Sheets(wshIndex).Names.Add name:=name, refersto:=refersto,
visible:=visible
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default common functions:where to put them?

instead of making your functions Private, put them in a common module
and put

Option Private

at the top. That way, they're unreachable to other projects (and XL's
macro dialog won't list them), but any Sub in the project can utilize
them.


In article .com,
wrote:

Since all are Private, I have had to make copies of them in each of the
5 modules that use them. Other than making them Public, how would the
group suggest I get away from this duplication?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default common functions:where to put them?

Thanks for the suggestion.

After posting y'day I came across a v similar solution from a posting
from Chip Pearson back in Jun 2000 and have been re-rranging my macro
ever since.

MGD

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
Second Most Common Value Skalp Excel Discussion (Misc queries) 6 May 9th 23 07:43 PM
MODE function where there are no common functions. DJFudd Excel Discussion (Misc queries) 1 July 22nd 09 03:41 AM
Combining two ranges based on common a common value ahmed[_3_] Excel Discussion (Misc queries) 5 April 18th 09 05:04 PM
Common footer but not common margins please -(Page 1 of 2) etc RajenRajput1 Excel Discussion (Misc queries) 9 August 26th 08 06:56 PM
Common Functions and Subs rbnorth Excel Discussion (Misc queries) 3 February 15th 06 10:07 PM


All times are GMT +1. The time now is 07:14 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"