I'm working on a project in VBA that has many modules (10+). I currently have the same functions inside each of the individual modules, but it seems that I could just house them centrally and make them available throughout the entire project. Is there a best practice for this? I don't want them to be available inside of Excel itself (eg, =FunctionCreated(B3)), if it makes a difference. Currently they are declared as Function .
Below is an example of a function that occurs in basically every module.
Function IsNumber(ByRef expression As Variant) As Boolean
IsNumber = Not (expression = "") And IsNumeric(expression)
End Function
答案 0 :(得分:4)
Put all the functions/sub in one module and decorate it with
'Option Private Module'
Option Explicit
'/ Prevents module's routine(s) from appearing as UDF (still works though)
'/ or Macro candidate.
Option Private Module
Public Function Test(lCtr As Long) As Long
Test = lCtr + 1
End Function