ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Default Dir (https://www.excelbanter.com/excel-programming/348764-default-dir.html)

GregR

Default Dir
 
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

Default Dir
 
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

GregR

Default Dir
 
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

Default Dir
 
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

GregR

Default Dir
 
Dave, thanks. I think I got it now

Greg


[email protected]

Default Dir
 
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




All times are GMT +1. The time now is 02:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com