2014-05-22 60 views
0

我在Power Point 2010中創建了一個下拉列表,該列表在保存文檔前工作得非常好。我在VBA中使用了以下代碼:保存PowerPoint 2010文檔時下拉列表(組合框)消失

Sub AddItemsToSelectedListBox() 

Dim oShape As Shape 

Set oShape = ActiveWindow.Selection.ShapeRange(1) 

With oShape.OLEFormat.Object 

' Add items to the list 

.AddItem ("Good") 

.AddItem ("Better") 

.AddItem ("Best") 

' You could work with other properties of the list or combo box here as well 

End With 

End Sub 

f5 + close。

通過進入視圖模式,下拉列表運行良好。但是,如果我保存我的Power Point文檔(以.pptm格式)並重新打開演示文稿,則列表不會再下降。如果我輸入VBA,代碼如下所示:

Sub AddItemsToSelectedListBox() 

Dim oShape As Shape 

Set oShape = ActiveWindow.Selection.ShapeRange(1) 

With oShape.OLEFormat.Object 

' Add items to the list 

.AddItem ("Good") 

.AddItem ("Better") 

.AddItem ("Best") 

' You could work with other properties of the list or combo box here as well 

End With 

End Sub 

Private Sub ComboBox1_Change() 

End Sub 

ComboBox_Change()部件是新的。 (爲什麼?) 有誰知道,如何生成一個下拉列表,倖存下來的保存過程? 非常感謝!

回答

0

當您雙擊組合框進入VBE時,將添加_Change子例程。

如果您從模塊中的子例程加載組合框,當您保存並重新打開時,它似乎不會保留這些值。

如果您從盒子中的事件中加載組合框,它看起來像您所期望的那樣工作。

例如:

Private Sub ComboBox1_GotFocus() 

Dim oShape As Shape 

Set oShape = ActivePresentation.Slides(1).Shapes("ComboBox1") 

With oShape.OLEFormat.Object 
.Clear 

' Add items to the list 

.AddItem ("Good") 

.AddItem ("Better") 

.AddItem ("Best") 

' You could work with other properties of the list or combo box here as well 

End With 
End Sub 
+0

但如果我增加更多的組合框(combobox1; combobox3; combobox5),只有最後一個組合框被保存,如果演示文稿重新打開工作。其他人都不見了:-( – user3665640

+0

其他人都沒了,或者他們在那裏但是空了? –

+0

其他人都是空的 輸入代碼,我看到在CB2中是CB1 + Private Sub的代碼ComboBox2_Change() End Sub 。在CB3中,它只保存了第一個組合框代碼!? – user3665640