2014-11-16 109 views
0

对于与Excel VBA完全不同的Powerpoint VBA,我还是个新手。我可以在Excel中做到这一点,但不是powerpoint,需要一些帮助。我需要在文本框中输入分数。之后按下按钮,形状将根据分数值填充颜色。得分越高,形状就越充满。以下是我的代码:如何在给定的条件下用颜色填充形状

Sub AddShape() 
Dim counter As Integer 
Dim TopValue As Integer 
TopValue = 500 
For counter = 1 To 5 
Set myDocument = ActivePresentation.Slides(2) 
With myDocument.Shapes.AddShape(Type:=msoShapeRectangle, Left:=144, _ 
Top:=TopValue, Width:=72, Height:=5) 
    .Name = "Rectangle" & counter 
    .Fill.Visible = msoFalse 
    .Line.DashStyle = msoLineSolid 
End With 
TopValue = TopValue - 50 
Next counter 
Dim tshape As Shape 
Set tshape = ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject(Left:=850, Top:=100, 
Width:=90, Height:=40, ClassName:="Forms.TextBox.1", Link:=msoFalse) 
End Sub 

Private Sub CommandButton1_Click() 
If CInt(TextBox1.Text) > 0 And CInt(TextBox1.Text) < 11 Then 
ActivePresentation.Slides(2).Shapes("Rectangle1").Fill.ForeColor.RGB = RGB(255, 0, 0) 
End If 
End Sub 

Private Sub TextBox1_Change() 
Me.TextBox1.SpecialEffect = fmSpecialEffectFlat 
End Sub 

Private Sub CommandButton1_Click内的代码看起来没有工作...请指教。我得到了及时运行所需的错误'424'对象。特定的代码赞赏,因为所有上述代码是从谷歌搜索直接复制。我没有太多的vba powerpoint知识。 非常感谢。

回答

0

您需要访问OLE对象及其属性与使用幻灯片上常规形状的方式有点不同。

相反TextBox1.Text的,使用

ActivePresentation.Slides(2).Shapes( “TextBox1中”)。OLEFormat.Object.Text