20260515指摘対応3

This commit is contained in:
guanxiangwei
2026-05-15 18:33:15 +09:00
parent fa8bd26757
commit 553148202c
5 changed files with 130 additions and 30 deletions
+33 -2
View File
@@ -31,8 +31,22 @@ Sub Fit_Button()
End Sub
Sub RefreshCache_Button()
Dim cacheSheets As Variant: cacheSheets = Array("M1", "M2", "Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "O1","O2")
Dim activeSheetName As String: activeSheetName = ActiveSheet.CodeName
' Determine which cache sheets to refresh based on ActiveSheet
Dim cacheSheets As Variant
If activeSheetName = "C1" Then
cacheSheets = Array("M1", "M2", "Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "O1", "O2")
ElseIf activeSheetName = "M1" Then
cacheSheets = Array("Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "O1", "O2")
ElseIf activeSheetName = "M2" Then
cacheSheets = Array("M1", "Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "O1", "O2")
Else
MsgBox "This sheet does not support cache refresh.", vbExclamation
Exit Sub
End If
' Validate and refresh cache
Dim sheetName As Variant
Dim ws As Worksheet
For Each sheetName In cacheSheets
@@ -49,8 +63,25 @@ Sub RefreshCache_Button()
End If
Next sheetName
Dim result As Boolean: result = RefreshAllCache()
' Refresh cache based on activeSheet
Dim result As Boolean: result = RefreshAllCache(activeSheetName)
If result = True Then
' Call active sheet's Refresh method
If ProcedureExists(activeSheetName, "Refresh") Then
On Error Resume Next
Set ws = ActiveSheet
On Error GoTo 0
If Not ws Is Nothing Then
Dim sheetConfDict As Object: Set sheetConfDict = GetSheetConfig()
Dim sheetConf As Object: Set sheetConf = sheetConfDict(activeSheetName)
Dim startRow As Long: startRow = sheetConf("StartRow")
Dim lastDataRow As Long: lastDataRow = GetLastDataRowInRange(ws)
Application.Run activeSheetName & ".Refresh", ws, startRow, lastDataRow
End If
Else
MsgBox "Sheet " & activeSheetName & " does not implement Refresh method.", vbExclamation
End If
MsgBox "master data reload successfully."
End If
End Sub
+25 -8
View File
@@ -573,15 +573,32 @@ Public Function GetSheetConfig() As Object
Set GetSheetConfig = sheetConfDict
End Function
Public Function RefreshAllCache() As Boolean
' refresh
Dim refreshCacheNames As Variant
refreshCacheNames = Array("Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "M1", "M1KukanDCache", "M2", "O1","O2", _
Public Function RefreshAllCache(Optional ByVal activeSheetName As String = "") As Boolean
' Fixed cache names
Dim fixedCaches As Variant
fixedCaches = Array("Z1", "Z2", "Z3", "Z4", "T1", "T2", "T3", "O1", "O2", _
"tokubetuList", "kenshuList", "oufukuList", "koutaiList", "higaitouList", "errorList")
Dim refreshCacheName As Variant
For Each refreshCacheName In refreshCacheNames
Call RefreshCache(refreshCacheName)
Next refreshCacheName
' Dynamic cache names based on activeSheet
Dim dynamicCaches As Variant
If activeSheetName = "C1" Then
dynamicCaches = Array("M1", "M1KukanDCache", "M2")
ElseIf activeSheetName = "M2" Then
dynamicCaches = Array("M1", "M1KukanDCache")
Else
dynamicCaches = Array()
End If
' Refresh fixed caches
Dim cacheName As Variant
For Each cacheName In fixedCaches
Call RefreshCache(CStr(cacheName))
Next cacheName
' Refresh dynamic caches
For Each cacheName In dynamicCaches
Call RefreshCache(CStr(cacheName))
Next cacheName
RefreshAllCache = True
End Function