Powerful PowerPoint for Educators: Using Visual Basic for Applications to Make PowerPoint Interactive


Download 1.37 Mb.
Pdf ko'rish
bet162/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   158   159   160   161   162   163   164   165   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

Sub AddStar()
ActivePresentation.SlideShowWindow.View.Slide.Shapes.AddShape _
(msoShape16pointStar, 100, 100, 100, 100)
End Sub
We have told VBA that we want our shape to be 100 pix els from the left of
the screen, 100 pix els from the top of the screen, 100 pix els wide, and 100 pix els
tall. This should fully define our shape. Hit Enter and now VBA starts to com-
plain again with the er ror in Figure 9.2.
Fig ure 9.2. Typ i cal Com pile Er ror
Now, VBA thinks we are missing an equals sign. This is a good ex ample of
a cryptic mes sage that can be a bit deceiving. In fact, we are miss ing an equals
sign, but simply add ing an equals sign (like we added a pa renthesis earlier)
won’t do the trick. The prob lem here (as is of ten the prob lem when VBA com-
plains about a missing equals sign) is that we have created an ob ject, and when
VBA creates an ob ject, it wants to put that ob ject in a variable (whether or not we
The Er ror in Red 157


ever want to do any thing with that ob ject again). Thus, we need to set a vari able
to point to the new ob ject (us ing
Set
because it is an object):
Sub AddStar()
Set myShape = _
ActivePresentation.SlideShowWindow.View.Slide.Shapes.AddShape _
(msoShape16pointStar, 100, 100, 100, 100)
End Sub
Now, we are in good shape! If you hit En ter, noth ing will turn red, but we
won’t know if it works un til we try it. Go back to PowerPoint, go to Slide Show
View, and click on your but ton. If all goes well, you will now have a new shape
on your slide.
Of course, if you click on the but ton a second time, noth ing will hap pen. Or,
it will ap pear that nothing hap pens. That is be cause you will create an other shape
on top of the first shape. If you go back into Edit View in PowerPoint, you can
see that you have two shapes by dragging one of the shapes out of the way.

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   158   159   160   161   162   163   164   165   ...   191




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling