早上好。我有兩個工作表的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」是正確的名稱。我已在每個工作表中多次提醒該名稱,索引和名稱都是正確的。
所以我希望你們能幫助我。感謝您的耐心和歉意,如果我的英語不夠清晰。隨意問的問題。