0
我的Excel VBA代碼有一個奇怪的問題。我在CSV電子表格中有一個日期字符串列,我想用雙引號括起來。 我在Excel中編寫了一個VBA腳本來實現這一點。但是,每次運行我的腳本時,日期字符串輸出都包含在三組雙引號中,而不是一組。VBA日期雙引號給出三重引號
我得到這個:
"""2015-11-11 00:00:00.40""",59845,-0.20375,3.447,2.0135,32.08286,12,32,11.6
取而代之的是:
"2015-11-11 00:00:00.40",59845,-0.20375,3.447,2.0135,32.08286,12,32,11.6
在哪裏可以我是想錯了?我曾嘗試使用CHAR(34)
和CHR(34)
來表示"
,但這並沒有幫助。 這是我的腳本:
Sub Quotations()
'
' Quotations Macro
'
'
Dim StrFile As String
StrFile = Dir("E:\Copy\*.csv")
' Create new workbook and assign to variable
Dim wb As Workbook
Do While Len(StrFile) > 0
Set wb = Workbooks.Add
Windows("PERSONAL.XLSB").Activate
wb.Activate
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;E:\Copy\" + StrFile, Destination:= _
Range("$A$1"))
.Name = "E:\Copy\" + StrFile
.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(2, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("J1").Select
ActiveCell.FormulaR1C1 = "=CHR(34)&RC[-9]&CHR(34)"
Range("J2").Select
Columns("J:J").ColumnWidth = 23.57
Range("J1").Select
Selection.AutoFill Destination:=Range("J1:J864000")
Range("J1:J864000").Select
Selection.Copy
Columns("A:A").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("J:J").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
'ActiveWindow.SmallScroll Down:=-6
ActiveWorkbook.SaveAs Filename:= _
"E:\Copy\quotes\" + StrFile, FileFormat:= _
xlCSV, CreateBackup:=False
ActiveWindow.Close savechanges:=False
StrFile = Dir
Loop
End Sub
我在做什麼錯了?在此先感謝您的幫助。
謝謝您的回覆。不幸的是,我正在使用的程序需要將文件作爲Excel以外的文本文檔打開。除了打開每個文件並使用查找和替換功能手動替換額外引號外,是否還有任何操作可以刪除多餘的引號? – Buzz