Skip to main content
Fixed typo in example
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Public Function Shout(arg1, arg2) ...
Private Function Whisper(arg1, arg2) ...

Set mod As Object = StdModAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.Whisper(1,2) 'fails - private method

Set mod = FancyAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.HiWhisper(1,2) 'succeeds'SUCCEEDS! - ITypeInfo lets us call private methods
Public Function Shout(arg1, arg2) ...
Private Function Whisper(arg1, arg2) ...

Set mod As Object = StdModAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.Whisper(1,2) 'fails - private method

Set mod = FancyAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.Hi(1,2) 'succeeds - ITypeInfo lets us call private methods
Public Function Shout(arg1, arg2) ...
Private Function Whisper(arg1, arg2) ...

Set mod As Object = StdModAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.Whisper(1,2) 'fails - private method

Set mod = FancyAccessor()
result1 = mod.Shout(1,2) 'fine
result2 = mod.Whisper(1,2) 'SUCCEEDS! - ITypeInfo lets us call private methods
edited body
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
'''Module Foo
Option Private Module
Private Sub Hi(ByVal who As String) 
    Debug.Print "Hello hello "; who
End Sub
'''

'''Module Bar (far away)
Dim fooModule as Object
Set fooModule = GetFancyAccessor("Foo")
fooModule.Hi "world" 'Call Private Hi method of modulwmodule Foo - prints "Hello hello world" as expected
 'NOTE: Private method, Option Private Module, password locked VBA project etc. all fine
'''
'''Module Foo
Option Private Module
Private Sub Hi(ByVal who As String) 
    Debug.Print "Hello hello "; who
End Sub
'''

'''Module Bar (far away)
Dim fooModule as Object
Set fooModule = GetFancyAccessor("Foo")
fooModule.Hi "world" 'Call Private Hi method of modulw Foo - prints "Hello hello world" as expected
 'NOTE: Private method, Option Private Module, password locked VBA project etc. all fine
'''
'''Module Foo
Option Private Module
Private Sub Hi(ByVal who As String) 
    Debug.Print "Hello hello "; who
End Sub
'''

'''Module Bar (far away)
Dim fooModule as Object
Set fooModule = GetFancyAccessor("Foo")
fooModule.Hi "world" 'Call Private Hi method of module Foo - prints "Hello hello world" as expected
 'NOTE: Private method, Option Private Module, password locked VBA project etc. all fine
'''
added 7 characters in body
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Add Demo and remove TLI dependency
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading
Minor clarifications
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading
Tweeted twitter.com/StackCodeReview/status/1498719763081617415
added 138 characters in body
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading
added 168 characters in body
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading
added 143 characters in body
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading
Source Link
Greedo
  • 2.4k
  • 2
  • 13
  • 35
Loading