Use String from another module

S

Silencer116

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?
 
G

Guest

at the top of one of the general modules in the declarations section above
all procedures/subs/functions.

Public Const Driver as String = "D:\"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top