fix: FilterTable/SorterTableを基本情報シート限定でなく全シートから名前で検索するよう修正

defaultSh(基本情報シート)固定で探していたため、ユーザーが別シートにテーブルを配置した際にBuildViewFromSheetが見つけられずViewが常に空になっていた。
FindListObjectByNameを追加し、ブック内の全シートを走査してテーブル名で検索するよう変更。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Kenichiro NOGI 2026-09-14 09:48:41 +09:00
parent d83d74afdc
commit 631e66242f

View File

@ -306,12 +306,26 @@ End Function
'テーブル名で探して読み取り、APIリクエストのViewパラメータに渡すDictionaryを組み立てる。
'セルの絶対位置には依存しないテーブルを移動しても動作する。各テーブルは1列目=項目名、2列目=値/昇降順とする。
'Filter・Sorterともに0件の場合はNothingを返すViewパラメータ自体を付与しないため
'ブック内の全シートを走査し、指定した名前のExcelテーブル(ListObject)を探す。見つからなければNothingを返す
Function FindListObjectByName(ByVal tblName As String) As ListObject
Dim sh As Worksheet
Dim tbl As ListObject
For Each sh In ThisWorkbook.Worksheets
On Error Resume Next
Set tbl = sh.ListObjects(tblName)
On Error GoTo 0
If Not tbl Is Nothing Then
Set FindListObjectByName = tbl
Exit Function
End If
Next sh
Set FindListObjectByName = Nothing
End Function
Function BuildViewFromSheet() As Object
Dim colFilter As New Dictionary
Dim filterTbl As ListObject
On Error Resume Next
Set filterTbl = defaultSh.ListObjects("FilterTable")
On Error GoTo 0
Set filterTbl = FindListObjectByName("FilterTable")
If Not filterTbl Is Nothing Then
If Not filterTbl.DataBodyRange Is Nothing Then
@ -328,9 +342,7 @@ Function BuildViewFromSheet() As Object
Dim colSorter As New Dictionary
Dim sorterTbl As ListObject
On Error Resume Next
Set sorterTbl = defaultSh.ListObjects("SorterTable")
On Error GoTo 0
Set sorterTbl = FindListObjectByName("SorterTable")
If Not sorterTbl Is Nothing Then
If Not sorterTbl.DataBodyRange Is Nothing Then