通勤認定エクセルツール対応12 M1 対応

This commit is contained in:
guanxiangwei
2026-05-28 12:58:08 +09:00
parent df9cd0a7ad
commit 50ef0c74cc
14 changed files with 602 additions and 199 deletions

View File

@@ -6,46 +6,25 @@ Public lastErrorMsg As String
' ============================================================
' Module Name: Common_Button
' Module Desc: Common Button handlers with centralized error handling
' Module Methods:
' - CSV_Import_Button
' - Validation_Button
' - CSV_Export_Button
' - Sort_Button
' - Filter_Button
' Module Desc: Common button handlers with centralized error handling
' Public Methods:
' - CSV_Import_Button (CSV import entry, binds to sheet button)
' - Validation_Button (validation entry, binds to sheet button)
' - CSV_Export_Button (CSV export entry, binds to sheet button)
' - Sort_Button (sort entry, binds to sheet button)
' - Filter_Button (filter entry, binds to sheet button)
' - Fit_Button (autofit column width, binds to sheet button)
' - RefreshCache_Button (refresh master cache)
' - RunValidationSilent (validate sheet, returns row count or -1)
' - HandleError (centralized error handler)
' Private Methods:
' - ValidateKukanCache
' - UpdateByMaster
' - Fit_Button
' - RefreshCache_Button
' ============================================================
' --- Public Button Functions ---
Sub CSV_Import_Button()
DO_CSV_Import ActiveSheet
End Sub
Sub Validation_Button()
Do_Validation ActiveSheet
End Sub
Sub CSV_Export_Button()
DO_CSV_Export ActiveSheet
End Sub
Sub Sort_Button()
Do_Sort ActiveSheet
End Sub
Sub Filter_Button()
Do_Filter ActiveSheet
End Sub
Sub Fit_Button()
Do_Fit ActiveSheet
End Sub
Sub RefreshCache_Button()
On Error GoTo ErrorHandler
Dim exitMsg As String
Dim activeSheetName As String: activeSheetName = ActiveSheet.CodeName
Debug.Print "1. Validate Z1~Z4, T1~T3, O1~O3 master data"
@@ -115,9 +94,10 @@ Private Sub UpdateByMaster(ByVal sheetName As String)
End Sub
' ============================================================
' CSV Import with error handler
' CSV Import entry point (binds to sheet button)
' ============================================================
Private Sub DO_CSV_Import(ws As Excel.Worksheet)
Public Sub CSV_Import_Button()
Dim ws As Worksheet: Set ws = ActiveSheet
On Error GoTo ErrorHandler
' Step 1: get csv encoding
@@ -137,9 +117,9 @@ Private Sub DO_CSV_Import(ws As Excel.Worksheet)
End If
' === Step 4: Clear all data rows before import ===
Call ClearDataRows(ws)
Application.ScreenUpdating = False
Application.EnableEvents = False
Call ClearDataRows(ws)
' === Step 5: Write CSV data to worksheet ===
Dim colLetters As Variant: colLetters = cfg("HeaderColumns")
@@ -169,10 +149,12 @@ FinallyExit:
End Sub
' ============================================================
' Do_Validation with HandleError
' Do_Validation entry point (binds to sheet button)
' ============================================================
Private Sub Do_Validation(ws As Excel.Worksheet)
Public Sub Validation_Button()
Dim ws As Worksheet: Set ws = ActiveSheet
On Error GoTo ErrorHandler
Application.EnableEvents = False
Dim result As Long: result = RunValidationSilent(ws)
@@ -197,22 +179,22 @@ Private Sub Do_Validation(ws As Excel.Worksheet)
Application.Run "M1.ValidateWarn", ws, lastDataRow
End If
GoTo FinallyExit
Do_Fit_Internal ws
Application.EnableEvents = True
Exit Sub
ErrorHandler:
Application.EnableEvents = True
HandleError "Do_Validation"
GoTo FinallyExit
Do_Fit_Internal ws
FinallyExit:
Do_Fit ws
ClearFormatsBelowLastDataRow ws
End Sub
' ============================================================
' CSV Export with HandleError
' CSV Export entry point (binds to sheet button)
' ============================================================
Private Sub DO_CSV_Export(ws As Excel.Worksheet)
Public Sub CSV_Export_Button()
Dim ws As Worksheet: Set ws = ActiveSheet
On Error GoTo ErrorHandler
' === Step 1: Validate all rows before export ===
@@ -284,10 +266,12 @@ ErrorHandler:
HandleError "DO_CSV_Export"
End Sub
' ============================================================
' Do_Sort with HandleError
' Do_Sort entry point (binds to sheet button)
' ============================================================
Private Sub Do_Sort(ws As Excel.Worksheet)
Public Sub Sort_Button()
Dim ws As Worksheet: Set ws = ActiveSheet
On Error GoTo ErrorHandler
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
@@ -303,9 +287,7 @@ Private Sub Do_Sort(ws As Excel.Worksheet)
End If
Dim sortRange As Range: Set sortRange = ws.Range(ws.Cells(startRow, ws.Range(startCol & "1").Column), ws.Cells(lastDataRow, ws.Range(endCol & "1").Column))
sortRange.Select
' Show sort dialog
Application.Goto sortRange
Application.Dialogs(xlDialogSort).Show
Exit Sub
@@ -313,15 +295,17 @@ ErrorHandler:
HandleError "Do_Sort"
End Sub
' ============================================================
' Do_Filter with HandleError
' Do_Filter entry point (binds to sheet button)
' ============================================================
Private Sub Do_Filter(ws As Excel.Worksheet)
Public Sub Filter_Button()
Dim ws As Worksheet: Set ws = ActiveSheet
On Error GoTo ErrorHandler
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
Dim sheetConf As Object: Set sheetConf = sheetConfDict(ws.CodeName)
' Check if auto filter is already on
If ws.AutoFilterMode Then
ws.AutoFilterMode = False
@@ -341,10 +325,14 @@ ErrorHandler:
HandleError "Do_Filter"
End Sub
Public Sub Fit_Button()
Do_Fit_Internal ActiveSheet
End Sub
' ============================================================
' Do_Fit with HandleError
' Do_Fit internal implementation
' ============================================================
Private Sub Do_Fit(ws As Excel.Worksheet)
Private Sub Do_Fit_Internal(ws As Excel.Worksheet)
On Error GoTo ErrorHandler
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()