fix: FilterTable/SorterTableを基本情報シート限定でなく全シートから名前で検索するよう修正
defaultSh(基本情報シート)固定で探していたため、ユーザーが別シートにテーブルを配置した際にBuildViewFromSheetが見つけられずViewが常に空になっていた。 FindListObjectByNameを追加し、ブック内の全シートを走査してテーブル名で検索するよう変更。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
d83d74afdc
commit
631e66242f
@ -306,12 +306,26 @@ End Function
|
|||||||
'テーブル名で探して読み取り、APIリクエストのViewパラメータに渡すDictionaryを組み立てる。
|
'テーブル名で探して読み取り、APIリクエストのViewパラメータに渡すDictionaryを組み立てる。
|
||||||
'セルの絶対位置には依存しない(テーブルを移動しても動作する)。各テーブルは1列目=項目名、2列目=値/昇降順とする。
|
'セルの絶対位置には依存しない(テーブルを移動しても動作する)。各テーブルは1列目=項目名、2列目=値/昇降順とする。
|
||||||
'Filter・Sorterともに0件の場合はNothingを返す(Viewパラメータ自体を付与しないため)
|
'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
|
Function BuildViewFromSheet() As Object
|
||||||
Dim colFilter As New Dictionary
|
Dim colFilter As New Dictionary
|
||||||
Dim filterTbl As ListObject
|
Dim filterTbl As ListObject
|
||||||
On Error Resume Next
|
Set filterTbl = FindListObjectByName("FilterTable")
|
||||||
Set filterTbl = defaultSh.ListObjects("FilterTable")
|
|
||||||
On Error GoTo 0
|
|
||||||
|
|
||||||
If Not filterTbl Is Nothing Then
|
If Not filterTbl Is Nothing Then
|
||||||
If Not filterTbl.DataBodyRange Is Nothing Then
|
If Not filterTbl.DataBodyRange Is Nothing Then
|
||||||
@ -328,9 +342,7 @@ Function BuildViewFromSheet() As Object
|
|||||||
|
|
||||||
Dim colSorter As New Dictionary
|
Dim colSorter As New Dictionary
|
||||||
Dim sorterTbl As ListObject
|
Dim sorterTbl As ListObject
|
||||||
On Error Resume Next
|
Set sorterTbl = FindListObjectByName("SorterTable")
|
||||||
Set sorterTbl = defaultSh.ListObjects("SorterTable")
|
|
||||||
On Error GoTo 0
|
|
||||||
|
|
||||||
If Not sorterTbl Is Nothing Then
|
If Not sorterTbl Is Nothing Then
|
||||||
If Not sorterTbl.DataBodyRange Is Nothing Then
|
If Not sorterTbl.DataBodyRange Is Nothing Then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user