當您保存從Excel CSV你有這些選項(與區域設置分隔符 - > 「」)
Option Explicit
Public Sub SaveCSV()
With ActiveWorkbook
.SaveAs Filename:="C:\x.csv", FileFormat:=xlCSV ' 6: -> ","
.SaveAs Filename:="C:\x.csv", FileFormat:=xlCSVMSDOS '24: -> ","
.SaveAs Filename:="C:\x.csv", FileFormat:=xlCSVWindows '23: -> ";"
.SaveAs Filename:="C:\x.csv", FileFormat:=xlCSVMac '22: -> ";"
End With
End Sub
在你的PowerShell腳本你使用(的FileFormat)
。
沒有可以更改Excel中的分隔符的另一個因素 - TextToColumns:
Public Sub testDelim()
setDelim "@"
End Sub
Public Sub setDelim(ByVal delim As String)
Application.DisplayAlerts = False
If 1 Then '-------------------------------------------------- Change delimiter
Range("A1") = "A" & delim & "1"
Range("A1").TextToColumns Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=False, _
Comma:=False, _
Space:=False, _
Other:=True, _
OtherChar:=delim
Range("A1:B1") = vbNullString
Else '------------------------------------------------------ Reset delimiter
Range("A1") = "x"
Range("A1").TextToColumns Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, _
Semicolon:=False, _
Comma:=False, _
Space:=False, _
Other:=False, _
OtherChar:=""
Range("A1") = vbNullString
End If
Application.DisplayAlerts = True
End Sub
當我做手工,我選擇了CSV既不DOS,MAC,......所以VBA之間的差異(,)和手動行爲(;)? – user310291
奇怪甚至23我得到「,」而不是「;」 (我在Windows 10上) – user310291
它可以在我的電腦上工作在windows7 – user310291