Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Use String from another module
Hey guys,
I hope you are going to understand what i'm trying to create. I've got this problem: I've got several Modules (subs) and Userforms. These Macro's are opening several files located somewhere. Now the problem is, that these Macro's will jam when everything is stored in an other location (For example, an USB Stick, is called driver D: on one PC but it could be F: on another one). So i thought, maybe it's handy to create a sub with one single line (a string perhaps?) that contains the very location of the files. So when i would change that statement, every macro would be changed. I'll Give you guys an example. Like in Module 1, i have Macro1. This Macro opens a workbook : Workbooks.Open("D:\Excel\Test.xls") This works when the USB stick is driver D: But when the driver is called F: it wouldn't work. The result is that i have to go through all modules and subs, changing the path's. I would like a sub in Module 2, that only contains the first part of the path. Like this: Sub Directory() Driver = "D:\" End Sub After that i would like the Sub in Module 1 uses the sub from module 2 like this: Sub OpenWB() Workbooks.Open (Cstr(Driver) & "Excel\Test.xls") End Sub But i don't have a clue how to realise this, so could anyone help me? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Use String from another module
at the top of one of the general modules in the declarations section above
all procedures/subs/functions. Public Const Driver as String = "D:\" -- Regards, Tom Ogilvy "Silencer116" wrote: Hey guys, I hope you are going to understand what i'm trying to create. I've got this problem: I've got several Modules (subs) and Userforms. These Macro's are opening several files located somewhere. Now the problem is, that these Macro's will jam when everything is stored in an other location (For example, an USB Stick, is called driver D: on one PC but it could be F: on another one). So i thought, maybe it's handy to create a sub with one single line (a string perhaps?) that contains the very location of the files. So when i would change that statement, every macro would be changed. I'll Give you guys an example. Like in Module 1, i have Macro1. This Macro opens a workbook : Workbooks.Open("D:\Excel\Test.xls") This works when the USB stick is driver D: But when the driver is called F: it wouldn't work. The result is that i have to go through all modules and subs, changing the path's. I would like a sub in Module 2, that only contains the first part of the path. Like this: Sub Directory() Driver = "D:\" End Sub After that i would like the Sub in Module 1 uses the sub from module 2 like this: Sub OpenWB() Workbooks.Open (Cstr(Driver) & "Excel\Test.xls") End Sub But i don't have a clue how to realise this, so could anyone help me? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
Run worksheet module code from workbook module? | Excel Programming | |||
Calls from sheet module to ThisWorkbook module | Excel Programming | |||
Excel VBA to search all macro code in Excel module for specific string criteria | Excel Programming | |||
Variable from a sheet module in a class module in XL XP | Excel Programming |