質問

I'm trying to create a function to write content, create new lines and new columns in the csv output file Here is the function I have:

Function WriteOutputToCSV(strCSVOutput)
'Check if file exists & write the data
On Error Resume Next

Set objUserCSV = objCSV.OpenTextFile(UserCSV, ForAppending)

If objCSV.FileExists(UserCSV) Then
   If CStr(strCSVOutput) = "*newline*" Then
    objuserCSV.Write vbcrlf
   Else if CStr(strCSVOutput) = "*newcolumn*" Then
    objuserCSV.value(columncount,1)="***"
    objuserCSV.Write vbcrlf
    columncount = columncount+1
   Else
    If CStr(InStr(1,strCSVOutput, ",")) Then
        strCSVOutput = Chr(34) & strCSVOutput & Chr(34)
    ElseIf CStr(Trim(strCSVOutput)) = "" Then
        strCSVOutput = " " 
    End If  
    objUserCSV.Write strCSVOutput & ","
   End If
Else    
' file DNE
End If

objUserCSV.Close
End Function

But it doesnt work(with a syntax error saying there is missing a end at line right before "' file DNE" and I have no idea why its wrong) also I don't think the newcolumn one is working. Any help? Thanks!

役に立ちましたか?

解決

You've got a space between the Else and if that shouldn't be there. This line:

Else if CStr(strCSVOutput) = "*newcolumn*" Then

should assumedly be:

ElseIf CStr(strCSVOutput) = "*newcolumn*" Then
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top