0
votes

Im new to Powerpoint VBA which is totally different from excel VBA. I can do it in excel but not powerpoint and need some help. I need to enter a score in the textbox. After that press a button, the shape will fill with color based on the score value. The higher the score, more shape will fill up. Below is my code:

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  

The code inside the Private Sub CommandButton1_Click doesn't seen to work... Please advise. I got prompt running error '424' object required. Specific code is appreciated as all the above code is direct copy from google search. I do not have much vba powerpoint knowledge. Thank you very much.

1

1 Answers

0
votes

You need to access OLE objects and their properties a bit differently from the way you work with regular shapes on slides.

Instead of TextBox1.Text, use

ActivePresentation.Slides(2).Shapes("TextBox1").OLEFormat.Object.Text