2
我想從excel中創建一個CSV文件,其中字段中的所有數據將位於雙引號內。 我發現這個代碼從一個類似的問題,它幾乎工程...excel中的CSV文件與雙引號內的字段
Sub CSVFile()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
If FName <> False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count > 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrTextStr = CurrTextStr & """" & CurrCell.Value & """" & ListSep
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)
Wend
Print #1, CurrTextStr
Next
Close #1
End If
End Sub
它讓我保存在一個CSV選定的領域,結果是這樣的:
"A1","B1","C3"
"A2","B2","C3"
我需要它也做的就是把一個逗號的最後一個字段後太喜歡這樣的:
"A1","B1","C3",
"A2","B2","C3",
我不知道這種代碼的想法,並可以使用一些幫助。
此外,如果這項工作如何保存在Excel表中的宏,所以我可以在任何時候使用它,我需要它。
感謝 約翰
它做了伎倆謝謝你隊友。 :) 我想「將包含此腳本的代碼模塊放在您的」個人「Excel工作簿中,但我不知道該怎麼做。 :( 我做了到現在爲止是: - ALT + F11 - 粘貼代碼 - 關閉並返回到Excel - Alt + F8運行和執行腳本 我第一次使用宏,我在這裏丟失了,你能否給我一個虛擬的假人 再次感謝您的幫助 – John 2013-03-27 18:46:34
John,這裏是一個關於從Excel MVP Ron de Bruin創建「PERSONAL」工作簿的概述http://www.rondebruin.nl /personal.htm – 2013-03-27 18:52:49