Microsoft Excel には、テキスト ファイルにデータを自動的にエクスポートするメニュー コマンドがないため、テキスト ファイルは区切り記号として引用符とコンマの両方でエクスポートされます。 たとえば、次のデータを含むテキスト ファイルを自動的に作成するコマンドはありません。
"Text1","Text2","Text3"
ただし、この機能は、Microsoft Visual Basic for Applications プロシージャを使用して Excel で作成できます。
詳細
Microsoft は、例示のみを目的としてプログラミング例を提供しており、明示または黙示にかかわらず、いかなる責任も負わないものとします。 これには、市販性または特定目的との適合性についての黙示の保証も含まれますが、これに限定はされません。 この記事は、説明されているプログラミング言語、手順を作成およびデバッグするために使用されているツールに読者が精通していることを前提にしています。 Microsoft サポート エンジニアは、特定のプロシージャの機能を説明するのに役立ちますが、これらの例を変更して、特定の要件を満たすために追加の機能を提供したり、プロシージャを構築したりすることはありません。
Sub QuoteCommaExport()
' Dimension all variables.Dim DestFile AsStringDim FileNum AsIntegerDim ColumnCount AsLongDim RowCount AsLong' Prompt user for destination file name.
DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")
' Obtain next free file handle number.
FileNum = FreeFile()
' Turn error checking off.OnErrorResumeNext' Attempt to open destination file for output.
Open DestFile For Output As#FileNum
' If an error occurs report it and end.
If Err <> 0 Then
MsgBox "Cannot open filename " & DestFile
End
End If
' Turn error checking on.
On Error GoTo 0
' Loop for each row in selection.
For RowCount = 1 To Selection.Rows.Count
' Loop for each column in selection.
For ColumnCount = 1 To Selection.Columns.Count
' Write current cell's text to file with quotation marks.
Print #FileNum, """" & Selection.Cells(RowCount, _
ColumnCount).Text & """";
' Check if cell is in last column.If ColumnCount = Selection.Columns.Count Then' If so, then write a blank line.
Print #FileNum,
Else
' Otherwise, write a comma.
Print #FileNum, ",";
EndIf' Start next iteration of ColumnCount loop.Next ColumnCount
' Start next iteration of RowCount loop.Next RowCount
' Close destination file.
Close #FileNum
End Sub