Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Opening File Open Dialog Box In A Specific Folder

This is a discussion on Opening File Open Dialog Box In A Specific Folder within the Excel Questions forums, part of the Question Forums category; Hi. I'm trying to develop a macro that brings up the File Open dialog box in a specific folder. I ...

  1. #1
    Board Regular
    Join Date
    May 2002
    Location
    San Diego
    Posts
    154

    Default Opening File Open Dialog Box In A Specific Folder

    Hi.

    I'm trying to develop a macro that brings up the File Open dialog box in a specific folder. I found the following code in several places on Mr. Excel but found it still opened up the dialog box in my C:\TEMP folder. Any ideas on how to get it to open in the U:\PAR folder?

    Thanks for you help!

    Mark

    Dim DIRECTORY As String
    Dim fileToOpen As Boolean
    DIRECTORY = "u:\par\"
    ChDir DIRECTORY
    fileToOpen = Application.GetOpenFilename("Excel Files (u:\par\*.xls), *.xls")
    Workbooks.Open fileToOpen

  2. #2
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Sub Test()
    ****Dim tmpFile

    ****ChDrive "U:\" 'change the drive also
    ****ChDir "U:\PAR"

    ****DoEvents
    ****
    ****tmpFile = Application.GetOpenFilename(FileFilter:="Microsoft Excel Files (*.xls),*.xls")
    ****
    ****If tmpFile <> False Then Workbooks.Open FileName:=tmpFile
    End Sub

  3. #3
    Board Regular
    Join Date
    May 2002
    Location
    San Diego
    Posts
    154

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Bingo!

    Thank you so much, TommyGun!

    Mark

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,948

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Just one thing, since the ChDrive will only use the first letter of the string that its passed, you could just use

    ChDrive "U"

    altough no "real" difference in there...
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  5. #5
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: Opening File Open Dialog Box In A Specific Folder

    True. My bad...

  6. #6
    Board Regular
    Join Date
    May 2002
    Location
    San Diego
    Posts
    154

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Thanks Juan! That's good to know.

  7. #7
    New Member
    Join Date
    Oct 2003
    Posts
    18

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Hi Guys

    I need help modifying this to fit what I need to do.

    Currently I am opening a dat file (txt based data file) and am using these parameters to load it into an excel sheet.

    Workbooks.OpenText Filename:= _
    "c:\data.DAT", Origin:=437, _
    StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
    Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array( _
    3, 1), Array(4, 1), Array(5, 1), Array(6, 1)), TrailingMinusNumbers:=True

    I would like to modify the above macro to give me a choice to open the dat file (that I can do), but using these parameters when opening the file (that I can't do).

    Thanks
    John

  8. #8
    Board Regular lord of the badgers's Avatar
    Join Date
    Jun 2003
    Location
    bristol, uk
    Posts
    208

    Default Re: Opening File Open Dialog Box In A Specific Folder

    O/T slightly.. what does DoEvents actually do? VBA Help was predictably baffling..

    (soz for the interruption )

  9. #9
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: Opening File Open Dialog Box In A Specific Folder

    In a very simple manner, DoEvents passes the "focus" of the processor back to the OS allowing it to clear anything in it's cue. I've found that sometimes it is necessary to add this line after changing drives/directories so that the process actually completes. You could probably remove it from this line of code, and it would still work correctly, but I just put it in there to be safe.

  10. #10
    New Member
    Join Date
    Oct 2003
    Posts
    18

    Default Re: Opening File Open Dialog Box In A Specific Folder

    Hi TommyGun,

    Since its your macro up there, you might be able to answer. Any ideas how to change it to allow me to specify those parameters above?

    My own macro from the macro recorder works fine, but I have to preset the location and name of the file. I would prefer to browse to open.

    Any ideas?

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com