0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

エクセル CSVファイルを読み込む VBA マクロ

Posted at

#はじめに
エクセルでCSV・テキストファイルを開けるのはいいのだが、
いちいち手作業で出力設定するのが面倒なのでマクロを書きました

Option Explicit

Sub getcsv()
    Dim st As String
    st = Application.GetOpenFilename()
    If st = "False" Then Exit Sub 'キャンセルなら処理終了

    Dim idx As Long
    idx = 1
    Dim Cnt As Long
    Dim Vst() As String
    
    Open st For Input As #1
    Do Until EOF(1)
        Line Input #1, st
        Vst = Split(st, ",")
        For Cnt = 0 To UBound(Vst)
            Range("A" & idx).Offset(0, Cnt).Value = Replace(Vst(Cnt), """", "")
        Next
        idx = idx + 1
    Loop
    Close #1
    
End Sub

読み込むだけなのでFSOを使うまでもないと思いましたので簡潔に書きました。

#おわりに
VBAネタあれば対応できます笑

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?