Excel Date formatting with hash marks for some reason - excel

The Problem
I've got a VBA program that exports data from one Excel file into a CSV. When it comes across a date, it formats it like #2016-06-14#. I'm assuming the hash marks (or octothorpe or pound sign or hashtag) are meant to indicate that the field is a date field. But, when I'm importing the CSV back into a different Workbook, the date will not come in no matter how I format the field. It still contains the # characters.
The Question
How can I get the date column to import as a YMD format date?
Appendix
Here's some code I'm using to export and import, for reference.
Export
Sub WriteCSV(writeRange As Range, fileName As String)
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = ActiveWorkbook.Path & "\Results\" & fileName & ".csv"
Debug.Print myFile
Open myFile For Output As #1
For i = 1 To writeRange.Rows.Count
For j = 1 To writeRange.Columns.Count
cellValue = writeRange.Cells(i, j).value
If j = writeRange.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next
Next
Close #1
End Sub
Import
Sub ReadCSV(targetCell As Range, filePath As String)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & filePath, Destination:=targetCell)
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 2
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
End Sub

Try outputing .text instead of .value.
Change this:
cellValue = writeRange.Cells(i, j).value
to this:
cellValue = writeRange.Cells(i, j).Text

Discard those #.
When I manually Save as a file as CSV, Excel does NOT put those # around the dates. Instead it writes the dates as they are defined in my regional settings (that is - for me - dd/mm/yyyy).
And when importing back, the recorder used array(...4...) for the date column, and it was imported correctly.
Anyway CSV really sucks if your are working in an international environment since it behaves differently according the the local machine settings. Being poorly defined, it's the last format I would use.

Related

Unnecessary value concatenation and Type Errors in Excel VBA

My VBA code takes a .txt file from a specific software output (Carlson Survey software) and does some calculations, then converts it into a .CSV file. I am specifically having issues with the calculation component, where one of my columns of the text file (brought into excel using comma separators) isn't doing the calculation I tell it, and is seemingly concatenating itself (removes everything after the decimal point). My assumption is, that because I am taking these values into an Array (which had to be set as string, or else I was getting type errors) which is set as a string, this is causing the concatenation after the decimal point. I am at a loss as to why the calculation doesn't appear to be running though, as the program seemingly executes fine.
And the VBA script for quick reference (specific section with problem is the 'Do data conversion' section:
Private Sub Workbook_Open()
Sheets("Sheet1").Cells.ClearContents
'---------------------------------------------------------------------------------------
'Choose and open the .TXT file for conversion
Dim answer As Integer
answer = MsgBox("Do you want to process a .TXT file for use in InfoSWMM?", vbYesNo + vbQuestion, "Select .TXT File")
If answer = vbNo Then
Exit Sub
End If
Dim Ret
Ret = Application.GetOpenFilename("Text Files (*.txt),*.txt")
If Ret <> False Then
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Ret, Destination:=Range("$A$1") _
)
.Name = "Sample"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
'---------------------------------------------------------------------------------------
'Do data conversion, SECTION NEEDS UPDATING LACKING FEATURES, BUGS
Dim row As Integer
Dim col As Integer
Dim i As Integer
Dim tester(3) As String 'Bug[1] related, type error (see below). String type fixes type error, but causes undesired concatenation
Dim col_test As Integer
Dim rim As Integer
For row = 1 To ActiveSheet.UsedRange.Rows.Count
If IsEmpty(ActiveSheet.Cells(row, 1).Value) = True Then
Exit For
End If
'Change these values in case feature code library is changed in Carlson, also need to add extra fields
If ActiveSheet.Cells(row, 5).Value = "SD" Or ActiveSheet.Cells(row, 5).Value = "WQ" Then
col_test = 20
rim = ActiveSheet.Cells(row, 4).Value
For i = 0 To 3
tester(i) = ActiveSheet.Cells(row, col_test).Value 'Bug[1] here, type error if not a String.
col_test = col_test + 4
Next i
ActiveSheet.Cells(row, 37).Value = rim - Application.Max(tester) 'Bug[2] here, not performing calculation.
End If
Next row
'---------------------------------------------------------------------------------------
'Save converted file as .CSV
MsgBox "Choose the desired save location for the .CSV file."
Dim InitialName As String
Dim PathName As Variant
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
InitialName = "sfm_output"
PathName = Application.GetSaveAsFilename(InitialFileName:=InitialName, fileFilter:="CSV (Comma delimited) (*.csv), *.csv")
ws.Copy
ActiveWorkbook.SaveAs Filename:=PathName, _
FileFormat:=xlCSV, CreateBackup:=False
MsgBox "Process completed successfully." & vbNewLine & "File saved to:" & vbNewLine & PathName
'---------------------------------------------------------------------------------------
'Close all Workbooks
Application.DisplayAlerts = False
Application.Quit
End Sub
Any help is greatly appreciated. Thanks.
Have you tried CSTRING or CINT functions?
For example:
tester(i) = CString(ActiveSheet.Cells(row, col_test).Value)

Extracting information from text file in VBA

I'm currently trying to extract data from a text file as part of an analytics challenge in my place of work. The text file is a bunch of data in lines with each heading/entry separated by a comma.
I've looked at several examples of text extraction online but the furthest I've gotten is getting one line in a single cell and then Excel freezing. All others have just frozen Excel after I've put in my conditions.
My current attempts involve the following:
Do Until EOF #1, textLine
Line Input #1, textLine
Do Until Count = Len(text line) + 1
Text = Text & Mid(textLine, Count, Count)
If Right(text, 1) = "," Then
textImport = Left(text, Count - 1)
Cells(rowCount, column count) = textImport
Text = ""
columnCount = columnCount + 1
Loop
rowCount = rowCount + 1
Loop
Can anyone advise where I'm going wrong? I can't share any of the data or the text file due to the nature of the challenge and the data involved.
QueryTable Import
You can do this:
Sub QueryImport()
Const cSheet As Variant = "Sheet1" ' Worksheet Name/Index
Const cSource As String = "A1" ' Source Range
Dim vntFile As Variant ' Source Array
vntFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If vntFile <> False Then
With ThisWorkbook.Worksheets(cSheet).QueryTables _
.Add(Connection:="TEXT;" & vntFile, _
Destination:=ThisWorkbook.Worksheets(cSheet).Range(cSource))
.Name = "Pets"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
End Sub
which will open a dialog where you can pick the file, which will then be imported to Excel, and then you can manipulate it further which is out of scope due to lack of information. Post part of the result in another question to get the desired result.
Try this if this is not a CSV that can be opened in Excel.
Sub readCSVLikeFile()
r = 1
Open "<path of the file> For Input As #1
While Not EOF(1)
Line Input #1, txtline
v = Split(txtline, ",")
Range(Cells(r, 1), Cells(r, UBound(v) + 1)) = v
r = r + 1
Wend
Close #1
End Sub

How to fix Run-time error '7' out of memory, which persists even after saving, closing, restarting computer

My Excel VBA macro produces "Run-time error '7': Out of memory"
The Excel document has a list of 5,500 csv documents in one sheet. The Macro goes through this list and, for each: a) puts their info into a consolidated output sheet; b) adds some formulas; and c) goes on to the next file.
After completing about 3,000 of them, the script hit the Out of memory error.
The main issue is that this problem persists after saving the file, closing Excel completely, re-opening Excel, and even restarting the computer. I also used Paste-Special to get rid of all formulas and replace with values. I also switched to Manual calculations.
I would like to find a way to prevent this error from occurring. At a minimum, if it occurs, I would like to be able to save, close, and re-open the file and keep going through the list 3,000 entries at a time.
I've read through all the previous questions and answers about Out of Memory errors, but none seem to have the issue persist after closing and reopening.
I am posting the relevant part of my code below. Debugger shows that the error occurred on the line: .Refresh BackgroundQuery:=False. I am running Windows 10, Excel 2007. Any help is appreciated. Thank you!
Sub test()
Dim filename As String
Dim outputsheet As String
Dim output_lastrow As Integer
Application.EnableEvents = False
For rep = 2 To 5502
filename = Sheets("Import Files").Range("A" & rep).Value ‘this takes the form of C:\Users\...\filename1.csv
outputsheet = "Summary"
output_lastrow = Sheets(outputsheet).Range("D999999").End(xlUp).Row
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" + filename, Destination:=Sheets(outputsheet).Range("$A" & output_lastrow + 2))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
output_lastrow = Sheets(outputsheet).Range("D999999").End(xlUp).Row + 1
Sheets(outputsheet).Range("A" & output_lastrow).Value = "Change"
Sheets(outputsheet).Range("B" & output_lastrow).Formula = "=R[-1]C"
Sheets(outputsheet).Range("C" & output_lastrow).Formula = "=R[-1]C"
Sheets(outputsheet).Range("C" & output_lastrow).AutoFill Destination:=Range("C" & output_lastrow & ":FP" & output_lastrow), Type:=xlFillDefault
End If
Dim wbconnection As WorkbookConnection
For Each wbconnection In ActiveWorkbook.Connections
If InStr(filename, wbconnection.Name) > 0 Then
wbconnection.Delete
End If
Next wbconnection
Next rep
Since you can just open a CSV file with Workbooks.Open in Ready-Only mode, and then copy the data like you would from a normal worksheet, try this:
Sub Test()
Dim filename As String
Dim outputsheet As String
Dim output_lastrow As Integer
Dim wbCSV AS Workbook
outputsheet = "Summary"
Application.EnableEvents = False
For rep = 2 To 5502
filename = Sheets("Import Files").Cells(rep, 1).Value ‘this takes the form of C:\Users\...\filename1.csv
output_lastrow = Sheets(outputsheet).Cells(Sheets(outputsheet).Rows.Count, 4).End(xlUp).Row
'Open CSV File
Set wbCSV = Workbooks.Open(Filename:=filename, ReadOnly:=True)
'Copy data to outputsheet
wbCSV.Worksheets(1).UsedRange.Copy Destination:=ThisWorkbook.Sheets(outputsheet).Cells(output_lastrow + 1, 1)
'Close CSV File
wbCSV.Close False
Set wbCSV = Nothing
Next rep
Application.EnableEvents = True
End Sub
If you store rep somewhere in the Workbook, and save it every so often (ThisWorkbook.Save) then even if it does crash, you can just resume your loop from the last point you saved

Loop through sub folders in a directory and import specified columns from .CSV files

I am trying to loop through a specific directory's sub folders and import specified columns from .CSV files.
I have a coding solution that does not loop through the sub folders.
Instead, it includes a Worksheet with File Path, File Destination and Column Number in three separate columns, but the sub folders are dynamic. They are changing in name and quantity.
File Path sheet:
Code:
Dim DL As Worksheet
Dim DFI As Worksheet
Set DL = ThisWorkbook.Sheets("DataList")
Set DFI = ThisWorkbook.Sheets("DataFeedInput")
DL.Rows("$3:$202").ClearContents
With DL.QueryTables.Add(Connection:="TEXT;C:\Users\ ... \MQL4\Files\Hist_#Corn_1440.csv", Destination:=Range("$A$3"))
.Name = "Hist_#Corn_1441"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 866
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(9, 1, 9, 9, 9, 9, 9, 1, 9, 9, 9, 9, 9, 9, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Dim i As Integer
For i = 4 To 642
Dim FileName As String
Dim OutputSheet As String
Dim ColNumber As String
FileName = DFI.Range("B" & i).Value
OutputSheet = DFI.Range("C" & i).Value
ColNumber = DFI.Range("D" & i).Value
With DL.QueryTables.Add(Connection:="TEXT;" & FileName, Destination:=DL.Range(ColNumber & "3"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 866
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(9, 9, 9, 9, 9, 9, 9, 1, 9, 9, 9, 9, 9, 9, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With
Next i
DL.Cells.EntireColumn.AutoFit
The problem with this approach is that if a .CSV file is not downloaded from the external source, I get an error stating that the file is missing.
Another issue is that this approach takes decades to finish the task.
I am looking for a solution that is not dependent on the File Path sheet, loops through the sub folders and extracts solely column 6 from the .CSV file.
In each of these folders I have one .CSV file:
I need to loop through each of them and create connection to Excel sheet, while importing solely column 6 from the .CSV.
Edit 1:
This is the File Path to the Sub Folders:
C:\Users\Betty\AppData\Roaming\MetaQuotes\Terminal\B4D9BCD10BE9B5248AFCB2BE2411BA10\MQL4\Files\Export_History
Edit 2:
What I learned so far, with the help of #Jeeped, is that I can loop through the folders with FileSystemObject, probably, go in to each of the folders and import column 6 from the .CSV.
It is quite difficult for me to get into how to merge the loop trough the folders and the .CSV import. If you can give me a hand with an outline procedure, I think I will be able to put it together and add it as edit to this question, if needed.
Edit 3:
I reckon I can use something of such for completing the task:
Code from #Tim Williams' answer to this question -> VBA macro that search for file in multiple subfolders
Sub GetSubFolders()
Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder
Set f = fso.GetFolder("file path")
For Each sf In f.SubFolders
'Use a loop to import only column 6 from every .CSV file in sub folders
Next
End Sub
#QHarr: Special thanks for the guidance!
After looking in to the FileSystemObject method for the purpose of looping trough Sub Folders and importing column 6 from a .CSV file in each Sub Folder in the next blank column in Worksheet HDaER, I managed to put together this code:
Dim fso As Object
Dim folder As Object
Dim subfolders As Object
Dim CurrFile As Object
Dim HDaER As Worksheet
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Users\Betty\AppData\Roaming\MetaQuotes\Terminal\B4D9BCD10BE9B5248AFCB2BE2411BA10\MQL4\Files\Export_History\")
Set subfolders = folder.subfolders
Set HDaER = Sheets("HDaER")
' IMPORT Col 6 FROM EACH .CSV FILE IN EACH SubFolder
LastCol = HDaER.Cells(2, HDaER.Columns.Count).End(xlToLeft).Column
For Each subfolders In subfolders
Set CurrFile = subfolders.Files
For Each CurrFile In CurrFile
With HDaER.QueryTables.Add(Connection:="TEXT;" & CurrFile, Destination:=HDaER.Cells(2, LastCol + 1))
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(9, 9, 9, 9, 9, 1, 9)
.Refresh BackgroundQuery:=False
LastCol = LastCol + 1
End With
Next
Next
' REMOVE SOURCE CONNECTIONS
For Each Connection In HDaER.QueryTables
Connection.Delete
Next Connection
' FREE MEMORY
Set fso = Nothing
Set folder = Nothing
Set subfolders = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
The Sub Folders that I currently have in the general Folder (Export_History) are:
The output that I get from the code is:
#QHarr: Please, let me know if you see anything that can be improved, especially in the QueryTables.Add part.

Run-time error '5' upon CSV import (Excel 2011, Mac)

I have been crawling the site for solutions to my problem. I use Excel 2011 for Mac OS X 10.10.5.
My situation is this:
I have a bunch of CSV files that i need to import into Excel for further statistical analysis. Here is an example of one of my CSV files (shared with google drive).
The data is delimited by comma, and should be imported to cell A1 in all sheets (for clarification, I do not wish to have all data in A1. That would be silly now, wouldn't it. CSV data should start here, and span across column A and B, down to row number ~1200 or whatever length it will be). The sheet a given CSV file is imported to should be named after the CSV file (without ".csv") as I will be calling data later by using the sheet names.
Using the import wizard is extremely tedious, and with 180 imports coming up, a VBA code / macro would help a lot as it would take me 6 very focused hours (and I like to do smart stuff in excel)
Currently I have a code which adds new sheets, but it does not work as
(1) Data is not imported - I get a runtime error '5' - Invalid procedure call or argument.
(2) Sheets are named with the file type extension .csv.
Any ideas as to why I get an error after this?:
With ActiveSheet.QueryTables.Add( _
Connection:="TEXT;" & Fname, _
Destination:=Range("A1"))l
Current code:
Sub CSVIMPORTTEST2()
Dim MyPath As String
Dim MyScript As String
Dim MyFiles As String
Dim MySplit As Variant
Dim N As Long
Dim Fname As String
Dim mybook As Worksheet
On Error Resume Next
MyPath = MacScript("return (path to documents folder) as String")
'Or use MyPath = "Macintosh HD:Users:YourUserName:Desktop:TestFolder:"
MyScript = "set applescript's text item delimiters to (ASCII character 10) " & vbNewLine & _
"set theFiles to (choose file of type " & _
" (""public.comma-separated-values-text"") " & _
"with prompt ""Please select a file or files"" default location alias """ & _
MyPath & """ multiple selections allowed true) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"return theFiles"
MyFiles = MacScript(MyScript)
On Error GoTo 0
If MyFiles <> "" Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
MySplit = Split(MyFiles, Chr(10))
For N = LBound(MySplit) To UBound(MySplit)
'Get file name only and test if it is open
Fname = Right(MySplit(N), Len(MySplit(N)) - InStrRev(MySplit(N), _
Application.PathSeparator, , 1))
Set mybook = Nothing
On Error Resume Next
Set mybook = Sheets.Add(After:=Sheets(Worksheets.Count))
mybook.Name = Fname
On Error GoTo 0
Next
Worksheets(Fname).Activate
With ActiveSheet.QueryTables.Add( _
Connection:="TEXT;" & Fname, _
Destination:=Range("A1"))
.Name = "CSV" & Worksheets.Count + 1
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlMacintosh
.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)
End With
End If
End Sub
Hope someone out there is able to help
Best regards Emil Hoeck
I'm not familiar with VBA-code or the parameters for Excel you're using, but you might want to check a few things:
First, you could do a debugprint of the filename(s) and the names of the sheets - just to make sure (especially Fname).
Now for the csv-file - the first lines look like this (don't mind the special characters here.. - these are ok in the file, UTF-8):
DATE,2015-11-30 08:30:36
SAMPLE RATE,1
BAR 1: Kløe
Range: 0 - 100
Labels: Ingen kløe - null - Værst tænkelige kløe
TIME,VALUE
0,0.0
1,0.0
and the parameters:
.FieldNames = True
.TextFileStartRow = 1
.TextFileCommaDelimiter = True
but your fieldnames start on row 8, and the data at row 9, while you want that data to start in cell A1. Maybe you should tune the parameters here.
Also, around line 610 there's another header:
600,63.0
601,63.0
BAR 2: Smerte
Range: 0 - 100
Labels: Ingen smerte - null - Værst tænkelige smerte
TIME,VALUE
0,0.0
1,0.0
You probably don't want that in your data either.
Don't know what this means, but looks strange if you only have 2 columns:
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

Resources