2023-03-03 14:29:04 -05:00
|
|
|
VERSION 1.0 CLASS
|
|
|
|
BEGIN
|
|
|
|
MultiUse = -1 'True
|
|
|
|
END
|
2023-03-09 10:32:58 -05:00
|
|
|
Attribute VB_Name = "shWalk"
|
2023-03-03 14:29:04 -05:00
|
|
|
Attribute VB_GlobalNameSpace = False
|
|
|
|
Attribute VB_Creatable = False
|
|
|
|
Attribute VB_PredeclaredId = True
|
|
|
|
Attribute VB_Exposed = True
|
2023-04-05 17:51:50 -04:00
|
|
|
'Option Explicit
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
|
|
|
|
' Dim pt As PivotTable
|
|
|
|
' Set pt = ActiveSheet.PivotTables("ptWalk")
|
|
|
|
' Dim intersec As Range
|
|
|
|
' Set intersec = Intersect(Target, pt.DataBodyRange)
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' If intersec Is Nothing Then
|
|
|
|
' Exit Sub
|
|
|
|
' ElseIf intersec.address <> Target.address Then
|
|
|
|
' Exit Sub
|
|
|
|
' End If
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Cancel = True
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Dim i As Long
|
|
|
|
' Dim j As Long
|
|
|
|
' Dim k As Long
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Dim ri As PivotItemList
|
|
|
|
' Dim ci As PivotItemList
|
|
|
|
' Dim df As Object
|
|
|
|
' Dim rd As Object
|
|
|
|
' Dim cd As Object
|
|
|
|
' Dim dd As Object
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Dim pf As PivotField
|
|
|
|
' Dim pi As PivotItem
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Set ri = Target.Cells.PivotCell.RowItems
|
|
|
|
' Set ci = Target.Cells.PivotCell.ColumnItems
|
|
|
|
' Set df = Target.Cells.PivotCell.DataField
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Set rd = Target.Cells.PivotTable.RowFields
|
|
|
|
' Set cd = Target.Cells.PivotTable.ColumnFields
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' ReDim handler.sc(ri.Count, 1)
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' handler.sql = ""
|
|
|
|
' handler.jsql = ""
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' For i = 1 To ri.Count
|
|
|
|
' If i <> 1 Then handler.sql = handler.sql & vbCrLf & "AND "
|
|
|
|
' If i <> 1 Then handler.jsql = handler.jsql & vbCrLf & ","
|
|
|
|
' handler.sql = handler.sql & rd(piv_pos(rd, i)).Name & " = '" & escape_sql(ri(i).Name) & "'"
|
|
|
|
' jsql = jsql & """" & rd(piv_pos(rd, i)).Name & """:""" & escape_json(ri(i).Name) & """"
|
|
|
|
' handler.sc(i - 1, 0) = rd(piv_pos(rd, i)).Name
|
|
|
|
' handler.sc(i - 1, 1) = ri(i).Name
|
|
|
|
' Next i
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' scenario = "{" & handler.jsql & "}"
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Call handler.load_config
|
|
|
|
' Call handler.load_fpvt
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'End Sub
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'Function piv_pos(list As Object, target_pos As Long) As Long
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Dim i As Long
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' For i = 1 To list.Count
|
|
|
|
' If list(i).Position = target_pos Then
|
|
|
|
' piv_pos = i
|
|
|
|
' Exit Function
|
|
|
|
' End If
|
|
|
|
' Next i
|
|
|
|
' 'should not get to this point
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'End Function
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'Function piv_fld_index(field_name As String, ByRef pt As PivotTable) As Integer
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' Dim i As Integer
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' For i = 1 To pt.PivotFields.Count
|
|
|
|
' If pt.PivotFields(i).Name = field_name Then
|
|
|
|
' piv_fld_index = i
|
|
|
|
' Exit Function
|
|
|
|
' End If
|
|
|
|
' Next i
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'End Function
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'Function escape_json(ByVal text As String) As String
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' text = Replace(text, "'", "''")
|
|
|
|
' text = Replace(text, """", "\""")
|
|
|
|
' If text = "(blank)" Then text = ""
|
|
|
|
' escape_json = text
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'End Function
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'Function escape_sql(ByVal text As String) As String
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
' text = Replace(text, "'", "''")
|
|
|
|
' text = Replace(text, """", """""")
|
|
|
|
' If text = "(blank)" Then text = ""
|
|
|
|
' escape_sql = text
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
2023-04-05 17:51:50 -04:00
|
|
|
'End Function
|
2023-03-22 12:05:02 -04:00
|
|
|
'
|
|
|
|
'
|
2023-03-03 14:29:04 -05:00
|
|
|
|