Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide VBA procedures from Excel application but not from other projects

Tags:

excel

vba

I know this is a long shot, but with the limitations in "Option Private Module" and even worse "Private Sub/Function", does anyone know if there is a way of hiding VBA procedures from the Excel application but not from other projects?

I have an XLAM with a subset of reusable functionality that I like to include and reference from new Excel projects, but using "Option Private Module" hinders this and if I omit it, a bunch of unusable or obscure functions and subs become visible and available to the application.

like image 849
Bjørn H. Sandvik Avatar asked Dec 06 '25 04:12

Bjørn H. Sandvik


1 Answers

  • Convert your standard modules in the XLAM to class modules (set to Public Not Creatable);
  • Create an additional Class Module that returns an instance (with a bit of additional work, the instance) of each such module; and
  • Create a single standard module with one property that returns the instance of the main class-entry module.

Class1:

Option Explicit

Public Sub IAmInvisible()

End Sub

ModuleEntry:

Option Explicit

Private mClass As New Class1

Public Property Get TheClass() As Class1
    Set TheClass = mClass
End Property
like image 57
Pieter Geerkens Avatar answered Dec 08 '25 00:12

Pieter Geerkens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!