[RESOLVED] [VBA in Access and Excel] Two modules with same name
I'm working on improving some VBA code in Excel, but the only time it's ever run is during the process of a huge macro in Access (the macro opens the Excel file and runs the macro in Excel and the Access macro does a bunch of stuff before and after). In Access, we have the following code:
Code:
Set ObjXLApp = CreateObject("excel.application")
Set objXLBook = ObjXLApp.workbooks.Open("whatever.xls")
ObjXLApp.Visible = True
ObjXLApp.Run ("SomeMacro")
ObjXLApp.Quit
My question is, which version of SomeMacro is run if the Excel workbook has two different modules with this name? They do basically the same thing, but I just want to know which one I can delete out. One is in the code for a worksheet, one is in a module, so my guess is the one in the module is the one that is run. Am I right? Thanks for any help!
Oh, similar question. In the Access file, there are three modules each with a function: Public Function getPath() As String
Which one is run when it's called? It is called only in the three modules that it is in. So, does it default to using the one in the same module? The code is all exactly the same, so again, not real important, but I'm trying to clean things up a bit.
Re: [VBA in Access and Excel] Two modules with same name
this wil help u
Code:
Application.Run ThisWorkbook.Name & "!Module1.temp"
where 'Module1' is module name and 'temp' is sub name
Re: [VBA in Access and Excel] Two modules with same name
Nope, it won't. I know how to make it call a specific one by using the module name. My question is what happens in the given situation described above.
Re: [VBA in Access and Excel] Two modules with same name
as i tested, it said that macro can't be found'
Re: [VBA in Access and Excel] Two modules with same name
Quote:
Originally Posted by
ActSciMan
My question is, which version of SomeMacro is run if the Excel workbook has two different modules with this name? They do basically the same thing, but I just want to know which one I can delete out. One is in the code for a worksheet, one is in a module, so my guess is the one in the module is the one that is run. Am I right? Thanks for any help!
As the worksheet is an object, you cannot run the sub etc in it without specifying the worksheet too (either directly as in Sheet(x).SomeMacro , or indirectly by running it from code within the worksheet).
In this case neither apply, so you are running the module based one.
Quote:
Oh, similar question. In the Access file, there are three modules each with a function: Public Function getPath() As String
Which one is run when it's called? It is called only in the three modules that it is in. So, does it default to using the one in the same module? The code is all exactly the same, so again, not real important, but I'm trying to clean things up a bit.
It does default to the most "local" one, thus the one in the same module.
As they are all the same, and declared as Public, you could delete two of the three (if you think it is apt for your situation).