Closed Thread
Results 1 to 6 of 6

Default Dir

  1. #1
    GregR
    Guest

    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


  2. #2
    Dave Peterson
    Guest

    Re: 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

  3. #3
    GregR
    Guest

    Re: 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


  4. #4
    Dave Peterson
    Guest

    Re: 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

  5. #5
    GregR
    Guest

    Re: Default Dir

    Dave, thanks. I think I got it now

    Greg


  6. #6

    Re: 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



Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1