是否可以在用户窗体中使用数据透视表?

是否有可能将数据透视表插入VBA中的用户窗体? 我看到了这个问题 ,但是我可以在右键菜单中findMicrosoft Office PivotTable control 。 我确实find了树视图,但这不是我不认为的完全一样的东西。

UPDATE

我正在创build一个库存工作簿供我的办公室使用。 我将允许其他人使用它来查看我们拥有的物品,并请求我们在库存中的物品。 我将使用这个用户Userform 。 我有一个自己的仪表板已经有几个数据透视表的工作簿。 有2我想在用户Userform使用。

普通用户将无法编辑工作簿,甚至无法更改显示的工作表,他们只需要查看要添加到此用户Userform的两个枢轴即可。

所以,最终的结果是最终用户将有一个数据透视表,让他们看到我们在库存中有什么,并要求它或发送一个电子邮件,将创build一个订购它的PO。

我一直在使用Excel很长一段时间,我从来没有听说过任何人需要这种组合(UserForm + PT),但无论如何,我做了一个快速的谷歌search,并提出了这一点。

 Option Explicit Dim cnnConnection As Object Private Sub Form_Load() Dim strProvider As String Dim view As PivotView Dim fsets As PivotFieldSets Dim c As Object Dim newtotal As PivotTotal strProvider = "Microsoft.Jet.OLEDB.4.0" ' Create an ADO object Set cnnConnection = CreateObject("ADODB.Connection") ' Set the provider and open the connection to the database cnnConnection.Provider = strProvider cnnConnection.Open "C:\pivottest.mdb" ' Set the pivot table's connection string to the cnnConnection's connection string PivotTable1.ConnectionString = cnnConnection.ConnectionString ' SQL statement to get everything from table1 PivotTable1.CommandText = "Select * from table1" ' Get variables from the pivot table Set view = PivotTable1.ActiveView Set fsets = PivotTable1.ActiveView.FieldSets Set c = PivotTable1.Constants ' Add Category to the Row axis and Item to the Column axis view.RowAxis.InsertFieldSet fsets("Category") view.ColumnAxis.InsertFieldSet fsets("Item") ' Add a new total - Sum of Price Set newtotal = view.AddTotal("Sum of Price", view.FieldSets("Price").Fields(0), c.plFunctionSum) view.DataAxis.InsertTotal newtotal view.DataAxis.InsertFieldSet view.FieldSets("Price") ' Set some visual properties PivotTable1.DisplayExpandIndicator = False PivotTable1.DisplayFieldList = False PivotTable1.AllowDetails = False End Sub Private Sub Form_Terminate() ' Remove reference to the ADO object Set cnnConnection = Nothing End Sub Private Sub PivotTable1_DblClick() Dim sel As Object Dim pivotagg As PivotAggregate Dim sTotal As String Dim sColName As String Dim sRowName As String Dim sMsg As String ' Get the selection object you double-clicked on Set sel = PivotTable1.Selection ' If it is a aggregate, you can find information about it If TypeName(sel) = "PivotAggregates" Then ' Select the first item Set pivotagg = sel.Item(0) ' Display the value MsgBox "The cell you double-clicked has a value of '" & pivotagg.Value & "'.", vbInformation, "Value of Cell" ' Get variables from the cell sTotal = pivotagg.Total.Caption sColName = pivotagg.Cell.ColumnMember.Caption sRowName = pivotagg.Cell.RowMember.Caption ' Display the row and column name sMsg = "The value is " & sTotal & " by " & sRowName & " by " & sColName MsgBox sMsg, vbInformation, "Value Info" End If End Sub 

看看你是否可以适应这个概念到你的具体设置。

https://support.microsoft.com/en-us/help/235542/how-to-use-the-pivottable-office-web-component-with-vb