Using With and Module to access variables, macros, functions in another module

JimminyJim

New Member
Joined
Mar 13, 2025
Messages
7
Office Version
  1. 365
Platform
  1. Windows
As per the heading: I'm trying to access variables, macros, functions in another module

I know that I can use (if calling from Module 1):

Module2.variable
Module2.sub
Module2.function

(assuming declared as public)

But how can i use 'With' statement to access multiple?

I've tried:

Code:
Dim myMod As VBIDE.VBComponent
Set myMod = ThisWorkbook.VBProject.VBComponents("Module2")

With myMod
   .variable = 15
   .sub
   .function
End With

I get "Object doesn't support this property or method" on each line item after 'With myMod'. Yes I have the extensibility library loaded.

This example might seem trivial, but in my actual project I wish to access many different variables and functions in many different modules to do bulk data retrieval and writing.

Is there something I can use to identify a module that can be used in a WITH statement?
 
Sorry RoryA, yes good point on the why!

I AM duplicating function names in multiple modules(intentionally), so I need to explicitly determine the module.

The need is twofold:
1) Remove code duplication (my last post)
2) Set the module to call at run time
 
Upvote 0
It sounds like you should be using classes then. It's not going to work with normal modules.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top