IT

横浜市オープンデータ加工マクロ

ファイル選択ダイアログ

Sub CommandButton1_Click()
  Dim FileName As Variant
  FileName = Application.GetOpenFilename("CSVファイル,*.csv")
  If FileName = False Then
    Exit Sub
  End If
  TextBox1.Text = FileName
End Sub
Sub CommandButton2_Click()
  Dim Sh As Worksheet
    Dim i As Integer
    FileName = Dir(TextBox1.Text)
  If FileName = "" Then
    Exit Sub
  End If
  With Workbooks.Open TextBox1.Text
        .SaveAs Replace(TextBox1.Text, ".csv", ".xlsx"), xlOpenXMLWorkbook
        .Close False
    End With
   Workbooks.Open Replace(TextBox1.Text, ".csv", ".xlsx")
    With ActiveWorkbook.Worksheets(1)
        For i = 2 To .Cells(1, 2).End(xlDown).Row Step i = i + 2
            .Range(.Cells.(i, 1), .Cells(i + 1, 1)).Select
            .Range(Selection, Selection.End(xlToRight)).Copy
            Set Sh = Worksheets.Add After:=ActiveSheet
            Sh.Name = .Cells(i, 1) 
   Range("B2").Select
            Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= False, Transpose:=True
        Nexi i
    End With
End Sub

コメント