早上好。我有两个工作表的Microsoft Excel宏启用工作簿:让我们说Sheet1和Sheet2。在Sheet2中,我有一个组合框(表单控件),它可以作为表格分类器。该表格也将在Sheet2中。该组合使用以下代码:宏在复制工作表中不起作用
Option Explicit
Sub DropDown4_Change()
Dim comboValue As String
Dim Key1ColumnIndex As Integer
Dim Key2ColumnIndex As Integer
'You can get the name by doing something like this in the immediate window: "? ActiveSheet.Shapes(1).OLEFormat.Object.Name"
comboValue = ActiveSheet.Shapes("Drop Down 4").ControlFormat.List(ActiveSheet.Shapes("Drop Down 4").ControlFormat.ListIndex)
Select Case comboValue
Case "By Keyphrase"
Key1ColumnIndex = 18
Key2ColumnIndex = 19
Case "By Region"
Key1ColumnIndex = 19
Key2ColumnIndex = 18
Case "Default"
Key1ColumnIndex = 1
Key2ColumnIndex = 1
End Select
Range("DataValues").sort Key1:=Range("DataValues").Cells(1, Key1ColumnIndex), _
Order1:=xlDescending, Header:=xlNo, DataOption1:=xlSortNormal, _
Key2:=Range("DataValues").Cells(1, Key2ColumnIndex), order2:=xlDescending
End Sub
此代码的工作原理与此工作表中的魅力类似。
我使用Aspose Cells for Java将此Excel工作簿用作模板以生成基于Sheet2副本(包含我的组合)的多个数据表的新工作簿,但问题是当我这样做时,组合不会不再像模板中那样工作了。
在这一行:
comboValue = ActiveSheet.Shapes("Drop Down 4").ControlFormat.List(ActiveSheet.Shapes("Drop Down 4").ControlFormat.ListIndex)
我得到这个错误:
Run-time error '438' Object doesn't support this property or method
它看起来像ControlFormat没有被确认为组合形状的有效方法。 无论您使用组合名称还是组合索引(在本例中始终为6),都会发生这种情况。 “Drop Down 4”是正确的名称。我已在每个工作表中多次提醒该名称,索引和名称都是正确的。
所以我希望你们能帮助我。感谢您的耐心和歉意,如果我的英语不够清晰。随意问的问题。