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


MsgBox ("The value of numCorrect is " & numCorrect)


Download 1.37 Mb.
Pdf ko'rish
bet165/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   161   162   163   164   165   166   167   168   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

MsgBox ("The value of numCorrect is " & numCorrect)
This will work most of the time. Un fortunately, certain kinds of errors will
not turn red and will not allow the pro cedure to run at all (for ex ample, instead of
mis spell ing 
myShape
, try mis spelling
RGB
). These are harder to find and are a
good reason to use some tricks to pre vent errors in the first place (see “An Ounce
of Pre ven tion”).
I’m Not See ing Red, But I’m Seeing Red 159


Com ment ing Out
Be cause the
MsgBox
method, in the pre vious section, works sometimes and 
doesn’t work other times, you might need an other old pro gram mer’s trick to
find your error: commenting out. Remember that ev erything on a VBA line after
a single quote is ig nored; that is, it is a comment. You can put a single quote at
the beginning of a line and that entire line will be ig nored. This is better than de-
leting the line because you still have the code there, and you can get it to run
again by de leting the single quote. Note that the VBA Ed itor turns com ments
green, so if you have anything that is green in your code, it is ignored by VBA.
Sub AddStar()
Dim myShape As Shape
MsgBox ("En 
tering the pro 
cedure AddStar.")
Set myShape = _
ActivePresentation.SlideShowWindow.View.Slide.Shapes.AddShape _
(mso16pointStar, 100, 100, 100, 100)
MsgBox ("I just added the shape, and I’m about to add some text.")
myShape.TextFrame.TextRange.Text = "Good job!"
MsgBox ("I just added some text, and I’m about to change the color.")
myShape.Fill.ForeColor.RGB = vbBlue
MsgBox ("Color is changed; now I’ll change the size.")
myShape.Height = 200

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   161   162   163   164   165   166   167   168   ...   191




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