Import CSV via QueryTables

R2ah1ze1l

Board Regular
Joined
Nov 10, 2017
Messages
93
I'm sorry this is close to redundant, however I have not seen where anyone has handled this: (forced to select '*.csv', strfile will not allow me to concatenate the file path/name with a .csv extension)
I do not want myself or other users to manually select the data, I want it pulled from the input fields I can control in my 'Data_Loc' sheet.
Code:
Set ws = ActiveWorkbook.Sheets("Data_Loc")
path_l = Range("c1").Value
file_1 = Range("c2").Value
'pick the file to work with, automation fails do to .csv vs .txt extensions
strfile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")
Set ws = ActiveWorkbook.Sheets("Update_CSV")
ws.Cells.Clear
'populates Update_CSV sheet with CSV values
With ws.QueryTables.Add(Connection:="TEXT;" & strfile, Destination:=ws.Range("A1"))
     .TextFileParseType = xlDelimited
     .TextFileCommaDelimiter = True
     .Refresh
End With

How can I further automate this process to stop the manual file selection?
Thank you for your assistance.
 
To share the issue I created for myself:
'path_1' continued to drop out information
changed to 'path_n'
'path_n' needed to be Dim As String (same to 'file_')
Lastly:
'.csv' would fail but '.CSV' functions.

This now allows what I was initially driving at. Thank you for your support!
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,762
Messages
6,126,740
Members
449,335
Latest member
Tanne

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