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
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