View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default 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?