Open .txt file with delimited columns from fixed folder

MyriamSL

New Member
Joined
Jul 12, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm currently trying to build an Excel Macro that would open the needed .txt file, with columns delimited by a comma, but from a fixed folder. My macro works perfectly fine to open the file I need, but I would like to make it better, and that the window that opens to let me choose my file always open in the same folder.

This is what I have so far:

Capture.PNG


I've searched forums to find how to open from a specific folder, but can't seem to combine that with the above code.

Thanks for your help!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi and welcome to MrExcel!

Change this name: "C:\work" to your initial folder.

Try this:
VBA Code:
Sub Open_Txt()
  With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select txt file"
    .Filters.Add "Txt Files", "*.txt"
    .AllowMultiSelect = False
    .InitialFileName = "C:\work"
    If .Show Then
      Workbooks.OpenText Filename:=.SelectedItems.Item(1), _
        Origin:=xlWindows, _
        StartRow:=1, _
        DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, _
        Tab:=False, _
        Semicolon:=False, _
        Comma:=True, _
        Space:=False, _
        Other:=False
    End If
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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