Need to use macro for import of CSV with option to select file location

ian_ticketserv

New Member
Joined
Jan 5, 2016
Messages
2
All,
I have been trying to get a macro created to select either a specific CSV file or several CSV files at the one time (all of the same source therefore same structure) and then open in Excel via the Data/From Text route.
At the same time, I need to set the file delimiters to Comma separated and also format several columns to be Text (so as to not lose leading zeroes in telephone numbers etc.
I started by recording a macro to bring the file in via data/From text but then when i tried to insert a variable file location option, i couldn't get anything to work.
This is the basic macro
Sub Macro3()
'
' Macro3 Macro
'


'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\Ian\Dropbox\@TicketServ\@Customers\Wodonga\DataConv SABO\Transaction Data\TransactionHistoryReport_2016-10-05__10-33-04_PM_ticketserv.csv" _
, Destination:=Range("$A$1"))
.Name = "TransactionHistoryReport_2016-10-05__10-33-04_PM_ticketserv"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

I then tried inserting a variable file select option following the TEXT option pointing to the file specific location in the macro but then it went downhill from there.
If anyone could offer some advice on the above, it would be appreciated.
If the macro could even just format all to TEXT rather than selectively do columns, I can handle the rest after the excel file is created and the n data mined.
Thanks in advance of any suggestions/advice
Cheers
Ian
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,200
Messages
6,123,598
Members
449,109
Latest member
Sebas8956

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