Can I declare somewhere in VBA a default directory, such as:
Dim DefaultDir as String
Set DefaultDir = "C:\Documents and Settings\GregR\My Documents\"
and have it apply to all my modules in my personal.xls. TIA
Greg
Can I declare somewhere in VBA a default directory, such as:
Dim DefaultDir as String
Set DefaultDir = "C:\Documents and Settings\GregR\My Documents\"
and have it apply to all my modules in my personal.xls. TIA
Greg
You can use a general module and declare the variable:
Option Explicit
Public DefaultDir as String
Then in some other module (workbook_open or auto_open), you can assign the value
to that variable:
Option Explicit
Sub Auto_Open()
defaultdir = "C:\Documents and Settings\GregR\My Documents\"
end sub
You don't need the Set command.
GregR wrote:
>
> Can I declare somewhere in VBA a default directory, such as:
>
> Dim DefaultDir as String
> Set DefaultDir = "C:\Documents and Settings\GregR\My Documents\"
>
> and have it apply to all my modules in my personal.xls. TIA
>
> Greg
--
Dave Peterson
Dave, what I am trying to do is assign the variable upon opening my
personal.xls, which has a number of modules, where there is a statement
such as:
SaveAs:"C:\Documents and Settings\GregR\My Documents\" &Folder &
Filename.
When I create, or copy in most cases, a module which has a save
statement, I am constantly repeating my default dir. What I am looking
for, and maybe you have given me the answer all ready, is something
which would look like:
SaveAs: defaultdir & Folder & Filename
Is what you have given me the answer and would I declare and add the
workbook open module to my personal.xls? TIA
Greg
I'd put this in a General module:
Option Explicit
Public DefaultDir as String
Sub Auto_Open()
defaultdir = "C:\Documents and Settings\GregR\My Documents\"
end sub
That should be enough (unless the variables are cleared for some reason).
GregR wrote:
>
> Dave, what I am trying to do is assign the variable upon opening my
> personal.xls, which has a number of modules, where there is a statement
> such as:
>
> SaveAs:"C:\Documents and Settings\GregR\My Documents\" &Folder &
> Filename.
>
> When I create, or copy in most cases, a module which has a save
> statement, I am constantly repeating my default dir. What I am looking
> for, and maybe you have given me the answer all ready, is something
> which would look like:
>
> SaveAs: defaultdir & Folder & Filename
>
> Is what you have given me the answer and would I declare and add the
> workbook open module to my personal.xls? TIA
>
> Greg
--
Dave Peterson
Dave, thanks. I think I got it now
Greg
Greg
Place this in a module in your Personal.xls outside of any procedures.
Public Const DefaultDir As String = _
"C:\Documents and Settings\GregR\My Documents\"
HTH
Paul
---------------------------------------------------------------------------------------------------------
>Can I declare somewhere in VBA a default directory, such as:
>
>Dim DefaultDir as String
>Set DefaultDir = "C:\Documents and Settings\GregR\My Documents\"
>
>and have it apply to all my modules in my personal.xls. TIA
>
>Greg
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks