GetOpenFileName initial Path

ShelleyBelly

New Member
Joined
Mar 2, 2011
Messages
44
Good Evening All,

I'm using the below code to select .xml files for import. I would like the import dialog box to remember the location of to last file as that is where the subsequent files for import are most likely to be and will therefore stop the user having to hunt through tiers of folders.

The last line of the code throws an error so i'm unsure if the first section is right either.


Code:
    If lastpath = vbNullString Then    
    ChDir "\"
    
    Else
    
    ChDir lastpath
    
    End If
    
    trackfile = Application.GetOpenFilename("XML Files (*.xml), *.xml", , "Import Track " & TrackNo, , True) 'import ytack1  text
  
    
    lastpath = trackfile.Path

Any guidance would be much appreciated

Tom
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Code:
  Dim sFile         As String
  Dim sPath         As String

  sFile = Application.GetOpenFilename(...)
  sPath = Left(sFile, InStrRev(sFile, "\"))
  ChDrive sPath
  ChDir sPath
 
Last edited:
Upvote 0
Hi Shg,

Thanks for the quick reply, unfortunately if I declare it as a string then it will not load as an array.

Any other suggestions?

Tom
 
Upvote 0
Sorry, crystal ball was dim.

If you allow multiselect, and the files have different paths, which path do do want to save as the default?
 
Upvote 0
Good plan. Remove the last argument to GetOpenFilename and proceed as suggested.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top