将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”,一个名为“ParaIcon”的矩形在Powerpoint文档的幻灯片7上...
有什么建议吗?
谢谢!
答案 0 :(得分: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