使用ComboBox更改Powerpoint VBA中的形状

时间:2017-09-06 20:15:43

标签: vba combobox powerpoint

我正在尝试为PowerPoint幻灯片创建一个ComboBox,它将根据用户的下拉选项更新幻灯片上的形状。到目前为止,我有以下代码,但ComboBox项目的选择不会触发形状的更改。有没有人看到我的代码中的缺陷以及为什么它不会触发我的形状变化?

Private Sub ComboBox1_Click()
ComboBox1.Clear
    If ComboBox1.ListCount = 0 Then
        With ComboBox1
                .AddItem "Increase", 0
                .AddItem "Decrease", 1
                .AddItem "No Effect", 2
        End With
    End If 
Dim sld As Slide
Dim shp1 As Shape
Dim l1 As Single
Dim l1m As Single
Dim t1 As Single
Dim t1m As Single

l1 = 3.49 * 72
l1m = 3.32 * 72
t1 = 5.38 * 72
t1m = 5.42 * 72


Set sld = Application.ActiveWindow.View.Slide

    If ComboBox1.Text = "Increase" Then
        Set shp1 = sld.Shapes.AddShape(msoShapeUpArrow, _
        Left:=l1, Top:=t1, Width:=0.35 * 72, Height:=0.28 * 72)

        ElseIf ComboBox1.Text = "Decrease" Then
        Set shp1 = sld.Shapes.AddShape(msoShapeDownArrow _
        , Left:=l1, Top:=t1, Width:=0.35 * 72, Height:=0.28 * 72)
        shp1.Name = "1"

        Else: ComboBox1.Text = "No Effect"
        Set shp3 = sld.Shapes.AddShape(msoShapeMathMinus, _
        Left:=lm1, Top:=tm1, Width:=0.71 * 72, Height:=0.31 * 72)
        End If
End Sub

0 个答案:

没有答案