0
0

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 1 year has passed since last update.

VBAでCSVのヘッダーを取得

Posted at

'VBAでCSVを取得しヘッダーのみを書き込む

Sub WriteCSVHeaderToActiveSheet()
Dim filePath As String
Dim delimiter As String
Dim headerRow As String
Dim headerItems() As String
Dim i As Integer

' CSVファイルのパスを指定してください
filePath = "C:\path\to\your\file.csv"

' CSVファイルの区切り文字を指定してください
delimiter = ","

' CSVファイルをテキストとして開き、ヘッダー行を読み込む
Open filePath For Input As #1
Line Input #1, headerRow
Close #1

' ヘッダー行を区切り文字で分割し、配列に格納する
headerItems = Split(headerRow, delimiter)

' 配列の要素をアクティブシートのA列に書き込む
For i = LBound(headerItems) To UBound(headerItems)
    Cells(i + 1, 1).Value = headerItems(i)
Next i

End Sub

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?