Hi
I'm facing issue when merging the csv files to excel. When below code is running, If I try to open a blank excel from desktop, the macro error out and stops.
Below is the code I'm using to merge the CVS files to excel.
For i = 1 To csvcount
Dim key As String: key = "csvfile:" & i
Dim csvinfor As String: csvinfor = info.Item(key)
Dim CsvInfoTokens() As String: CsvInfoTokens = Split(csvinfor, "|")
Dim CsvFilePath As String: CsvFilePath = CsvInfoTokens(0)
Dim CsvDelimEncoded As String: CsvDelimEncoded = CsvInfoTokens(1)
Dim CsvSheetName As String: CsvSheetName = CsvInfoTokens(2)
Dim CsvCellAddress As String: CsvCellAddress = CsvInfoTokens(3)
If CsvSheetName = "SWDATA" Then
ThisWorkbook.Worksheets(CsvSheetName).Visible = True
ThisWorkbook.Worksheets(CsvSheetName).Select
End If
Dim LastAddress As String: LastAddress = Worksheets(CsvSheetName).UsedRange.SpecialCells(xlCellTypeLastCell).address(False, False)
'Worksheets(CsvSheetName).Visible = False
'In case the new data set has smaller than existing; possible when items have been deleted.
ThisWorkbook.ForceFullCalculation = True
ThisWorkbook.Worksheets(CsvSheetName).Range(CsvCellAddress, LastAddress).Clear
'Live-merge CSV.
With ThisWorkbook.Worksheets(CsvSheetName).QueryTables.Add(Connection:="TEXT;" & CsvFilePath, Destination:=Range(CsvSheetName & "!" & CsvCellAddress))
.FieldNames = True
.RowNumbers = True
.FillAdjacentFormulas = True
.RefreshOnFileOpen = False
.RefreshStyle = Excel.XlCellInsertionMode.xlOverwriteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "~"
.TextFileStartRow = 1
.PreserveFormatting = True ' Code to support UNICODE Charcters if any.
.TextFileTextQualifier = xlTextQualifierDoubleQuote
' Treat numbers as en-US
.TextFileThousandsSeparator = ","
.TextFileDecimalSeparator = "."
' CHANGED FOR NIDEC fOR JAPANESE CHARACTERS
.TextFilePlatform = 65001
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileTrailingMinusNumbers = True
.Refresh
End With
Dim MergeTimeSeconds As Double: MergeTimeSeconds = Round(Timer - MergeStartTime, 2)
'If Not Actions.logObject Is Nothing Then Call Actions.logObject.Log("Merged into " & CsvSheetName & " (" & FileLen(CsvFilePath) & "b in " & MergeTimeSeconds & "s).", DEBUG_LEVEL)
'1100 PopupAnswer = Shell.Popup("Merged into " & CsvSheetName & " (" & FileLen(CsvFilePath) & "b in " & MergeTimeSeconds & "s).", 0, FriendlyTitle, 64)
Kill CsvFilePath
Next i
Bookmarks