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?

あああ

Posted at

Sub ConvertCSVtoXLSX_KeepLeadingZeros()
Dim csvPath As String
Dim xlsxPath As String
Dim ws As Worksheet
Dim qt As QueryTable
Dim wb As Workbook

' フルパスを設定(必要に応じて変更)
csvPath = "C:\Users\YourName\Desktop\AAA.csv"
xlsxPath = Replace(csvPath, ".csv", ".xlsx")

' 新しいブックを作成
Set wb = Workbooks.Add(xlWBATWorksheet)
Set ws = wb.Sheets(1)

' クエリテーブルでCSVを文字列として読み込み
Set qt = ws.QueryTables.Add(Connection:="TEXT;" & csvPath, Destination:=ws.Range("A1"))
With qt
    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
    .TextFileColumnDataTypes = GetColumnTypes(csvPath)
    .Refresh BackgroundQuery:=False
End With

' .xlsx形式で保存
Application.DisplayAlerts = False
wb.SaveAs Filename:=xlsxPath, FileFormat:=xlOpenXMLWorkbook
wb.Close SaveChanges:=False
Application.DisplayAlerts = True

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?