【问题标题】:Passing a specific shape as a function argument将特定形状作为函数参数传递
【发布时间】:2012-08-23 22:09:01
【问题描述】:

在应用程序中使用 Powerpoint 2010 和 MS Visual Basic:

我正在尝试将特定形状作为参数传递...尝试了不同的语法或方法,但没有运气,它似乎阻止了在函数之间使用 oShape 变量。

函数 ClickBtn1() 将 oShape 变量设置为要修改的形状的名称,并调用修改函数 Incre()。

Incre() 将数值设置为 12,将文本范围从形状更新为它,然后将前景色更改为 10、10、10,然后重新绘制幻灯片...

我所拥有的是这样的:

Dim oShape As Shape
Dim x As Long

Sub ClickBtn1()
MsgBox "Inside ClickBtn1"
oShape = ActivePresentation.Slides(7).Shapes("ParaIcon")
Incre
End Sub

Sub Incre()
MsgBox "inside Incre"
x = 12
oShape.TextFrame.TextRange.Text = x
oShape.Fill.ForeColor.RGB = RGB(10, 10, 10)
SlideShowWindows(7).View.GotoSlide (SlideShowWindows(7).View.Slide.SlideIndex)
End Sub

我有一个箭头形状,其动作设置为“运行宏 ClickButton1”,在 Powerpoint 文档的幻灯片 7 上有一个名为“ParaIcon”的矩形...

有什么建议吗?

谢谢!

【问题讨论】:

    标签: variables powerpoint argument-passing shapes


    【解决方案1】:

    我会这样做;避免使用全局变量并使用 SET 将对象引用分配给变量。

    Sub ClickBtn1()
        Dim oShape as Shape
        MsgBox "Inside ClickBtn1"
        SET oShape = ActivePresentation.Slides(7).Shapes("ParaIcon")
        Incre oShape    
    End Sub
    
    Sub Incre(oShape as Shape)
        Dim x as Long
        MsgBox "inside Incre"
        x = 12
    
        ' Convert numbers to string before assigning text
        oShape.TextFrame.TextRange.Text = Cstr(x)
    
        oShape.Fill.ForeColor.RGB = RGB(10, 10, 10)
        SlideShowWindows(7).View.GotoSlide (SlideShowWindows(7).View.Slide.SlideIndex)    
    End Sub
    

    【讨论】:

    • 完美运行!非常感谢!
    猜你喜欢
    • 2019-07-20
    • 2021-11-11
    • 1970-01-01
    • 2021-04-13
    • 2023-04-02
    • 2013-01-27
    • 1970-01-01
    相关资源
    最近更新 更多