Attribute VB_Name = "gy07_edit1" ' 各銘柄の日足データと財務情報を取得するためのクエリファイルを作成する ' 入力ファイル:"C:\mysql\mysqldata\csv\yp*????.csv" Option Base 1 Sub gy07_edit1() initial_time = Timer ' 開始時刻 '警告の表示を停止 Application.DisplayAlerts = False ' CSVファイル高速読み込み。CSVファイルをTXTファイルでSheet1に開く Dim corp_list(5000, 3) As String ' 行数5000列数3を確保する(カラム数は正確に) Dim list_idx As Integer ' 会社リストファイルの会社コード数 Const csv_dir As String = "C:\mysql\mysqldata\csv" ' CSVファイルのディレクトリ Const read_csv_name As String = "gy01_corpgrp.csv" ' CSVファイル名 If Dir(csv_dir & "\" & read_csv_name) <> read_csv_name Then MsgBox "ファイル「" & read_csv_name & "」はありません" Exit Sub End If Application.StatusBar = "( " & read_csv_name & " )読み込み中" ' CSVファイル読み込み list_idx = 1 Open csv_dir & "\" & read_csv_name For Input As #1 Do Until EOF(1) Input #1, corp_list(list_idx, 1), corp_list(list_idx, 2), corp_list(list_idx, 3) list_idx = list_idx + 1 Loop Close #1 ' セルに書き込み。必要なのは第1フィールド ' Sheets("Sheet1").Range(Cells(1, 1), Cells(list_idx - 1, 1)).Value = corp_list ' ----------------------------------------------------------------------------- Dim open_f_name As String Dim corp_list_idx As Integer corp_list_idx = 1 Do While corp_list_idx < list_idx open_f_name = Dir(csv_dir & "\yp" & corp_list(corp_list_idx, 1) & "*.csv") If open_f_name <> "" Then Workbooks.Open Filename:=csv_dir & "\" & open_f_name ' データ編集 ' 注意:処理時間2倍近くかかるので、ネット接続時間を短縮するために後で処理することを推奨する ' カラムAの日付型データを8桁の整数型へ変換 For Each date_data_row In Range(Cells(1, 1), Cells(8000, 1)) date_data_row.Value = Format(date_data_row.Value, "yyyymmdd") date_data_row.NumberFormatLocal = "G/標準" Next date_data_row ActiveWorkbook.SaveAs Filename:= _ csv_dir & "\" & open_f_name, FileFormat:=xlCSV, CreateBackup:=False ActiveWindow.Close End If corp_list_idx = corp_list_idx + 1 Application.StatusBar = "STATUS( " & corp_list_idx & "ファイル:" & Left(Str((Timer - initial_time) / 60), 4) & "分経過 )" Loop End Sub