' --- 変数宣言 --- Dim conf_ws As Worksheet: Set conf_ws = Worksheets("config") Dim new_ws As Worksheet: Set new_ws = Worksheets("new") Dim old_ws As Worksheet: Set old_ws = Worksheets("old")
Dim start_row AsLong Dim end_row AsLong Dim start_column AsLong Dim end_column AsLong
Dim diff_cell_color As Variant Dim diff_area_border AsBoolean
' 最終行・列の自動取得 If end_row < 1Then If new_ws.UsedRange.Rows.Count >= old_ws.UsedRange.Rows.Count Then end_row = new_ws.UsedRange.Rows(new_ws.UsedRange.Rows.Count).Row Else end_row = old_ws.UsedRange.Rows(old_ws.UsedRange.Rows.Count).Row EndIf EndIf
If end_column < 1Then If new_ws.UsedRange.Columns.Count >= old_ws.UsedRange.Columns.Count Then end_column = new_ws.UsedRange.Columns(new_ws.UsedRange.Columns.Count).Column Else end_column = old_ws.UsedRange.Columns(old_ws.UsedRange.Columns.Count).Column EndIf EndIf
' 差分セルに色付け For i = start_row To end_row For j = start_column To end_column If new_ws.Cells(i, j) <> old_ws.Cells(i, j) Then new_ws.Cells(i, j).Interior.Color = diff_cell_color EndIf Next j Next i
' 比較範囲全体に外枠 If diff_area_border Then new_ws.Activate new_ws.Range(Cells(start_row, start_column), Cells(end_row, end_column)).BorderAround Weight:=xlMedium EndIf
withopen('new.txt', newline='', encoding="utf-8") as new_csv: dat = csv.reader(new_csv, delimiter=',', quotechar='"') for line in dat: new_sheet.append(line)
withopen('old.txt', newline='', encoding="utf-8") as old_csv: dat = csv.reader(old_csv, delimiter=',', quotechar='"') for line in dat: old_sheet.append(line)