Примечание в ячейке Excel, привязанное к ячейке сводной таблицы
#38256631
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
Serge 007,
excel 2013
текст всего модуля, там есть CreateComment
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171.
Sub CreateShortcut()
Dim myBar As CommandBar
Dim myItem As CommandBarControl
Dim pmyItem As CommandBarControl
Set myBar = CommandBars.Item("PivotTable Context Menu")
Set myItem = myBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
With myItem
.Caption = "Äåòàëèçàöèÿ ïî ÖÔÎ"
.OnAction = "FillCommentForCFO"
End With
Set myItem = myBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
With myItem
.Caption = "Äåòàëèçàöèÿ ïî Êîíòàðãåíòàì"
.OnAction = "FillCommentForContractors"
End With
Set myItem = myBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
With myItem
.Caption = "Äåòàëèçàöèÿ ïî Àíàëèòèêàì"
.OnAction = "FillCommentForAnalytics"
End With
End Sub
Sub FillCommentForCFO()
Call FillCommentForPivotCell(1, Selection)
End Sub
Sub FillCommentForContractors()
Call FillCommentForPivotCell(2, Selection)
End Sub
Sub FillCommentForAnalytics()
Call FillCommentForPivotCell(3, Selection)
End Sub
Sub FillCommentForPivotCell(CommmentType As Integer, Target As Range)
'Dim Target As Range
Dim Comment As String
Dim cell As PivotCell
If Err.Number <> 0 Then GoTo done
If TypeName(Target.Value) <> "Double" Then GoTo done
On Error GoTo done
Set cell = Target.PivotCell
On Error GoTo 0
If cell.PivotCellType = xlPivotCellValue Then
Comment = GenerateMDX(cell, CommmentType)
Call CreateComment(Comment, Target)
End If
done:
On Error GoTo 0
End Sub
Function GenerateMDX(pcell As PivotCell, CommmentType As Integer)
Dim pcache As PivotCache
Dim pf As PivotField
Dim mdx As String
Dim axe As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Select Case CommmentType
Case 1
axe = "[DimCFOAndOrg].[CFO ID].[CFO ID]"
Comment = "ÖÔÎ:"
Case 2
axe = "[Dim Contractors].[Contractor ID].[Contractor ID]"
Comment = "Êîíòðàãåíòû:"
Case 3
axe = "[Dim Analytics].[Analytic ID].[Analytic ID]"
Comment = "Àíàëèòèêè:"
End Select
'Dim Comment As String
'Set Comment = ""
Set pt = pcell.Parent
Set pcache = pt.PivotCache
If Not pcache.IsConnected Then
pcache.MakeConnection
End If
Set adoCmd = New ADODB.Command
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = pcache.ADOConnection
Set Conn = adoCmd.ActiveConnection
'recs.CommandText = "select non empty {measures.members} on 0, non empty " & axe & " on 1 from (select " & pcell.mdx & " on 0 from [" & pcache.CommandText & "])"
'Set resc = adoCmd.Execute
rs.Open ("select non empty {measures.members} on 0, non empty " & axe & " on 1 from (select " & pcell.mdx & " on 0 from [" & pcache.CommandText & "])")
Count = 0
While Not rs.EOF
Count = Count + 1
Comment = Comment & vbCrLf & " " & Count & ") " & rs(0) & ": " & rs(1) & ""
rs.MoveNext
Wend
rs.Close
GenerateMDX = Comment
End Function
Sub CreateComment(txt As String, Target As Range)
If Not (Target.Comment Is Nothing) Then
Target.Comment.Text Text:=txt
Else
Target.AddComment (txt)
End If
End Sub
Sub DeleteShortcut()
Dim myBar As CommandBar
Dim myItem As CommandBarControl
Set myBar = CommandBars.Item("PivotTable Context Menu")
Set myItem = myBar.Controls.Item("Äåòàëèçàöèÿ ïî ÖÔÎ")
If Not (myItem Is Nothing) Then
myItem.Delete
End If
Set myItem = myBar.Controls.Item("Äåòàëèçàöèÿ ïî Àíàëèòèêàì")
If Not (myItem Is Nothing) Then
myItem.Delete
End If
Set myItem = myBar.Controls.Item("Äåòàëèçàöèÿ ïî Êîíòàðãåíòàì")
If Not (myItem Is Nothing) Then
myItem.Delete
End If
End Sub
Sub CommentsRefresh()
Dim cell As Range
i = 1
Dim Sh As Worksheet
Set Sh = ActiveSheet
For Each Comment In Sh.Comments
Set cell = Comment.Parent.Cells
Select Case Left(Comment.Text, 1)
Case "Ö"
Call FillCommentForPivotCell(1, cell)
Case "Ê"
Call FillCommentForPivotCell(2, cell)
Case "À"
Call FillCommentForPivotCell(3, cell)
End Select
Next Comment
End Sub
|
|