LoginSignup
3
3

More than 5 years have passed since last update.

ExcelファイルをCSVファイルに変換する

Posted at
    CsvFile = Split(TargetFile, ".")(0) & ".csv"
    Workbooks.Open (Path & "\" & TargetFile)
    Sheets(1).Select
    ActiveWorkbook.SaveAs Filename:=Path & "\" & CsvFile, FileFormat:=xlCSV
    ActiveWindow.Close

ファイルを保存する際に、保存するフォーマットを指定します。例えばテキスト形式やCSV形式での保存を行う場合に使います。

設定するには「SaveAs」メソッドの引数に「FileFormat」を設定します。

Dim book1 As Workbook

Set book1 = Workbooks("VBAsample.xls")

book1.SaveAs Filename:="C:¥excelsample¥OtherFile.xls", _
    FileFormat:="xlCSV"

指定できるファイルフォーマットは以下の通りです。

定数 フォーマット 拡張子
xlCSV CSV(カンマ区切り) *.csv

その他は、http://www.officepro.jp/excelvba/book_new/index9.html
を参照

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3