On a Windows computer, the VBA Ed itor of ten tries to give you helpful suggestions. You might have no ticed that when you type a dot, sometimes a box pops up with pos sibilities for what to type next. See Fig ure 9.3 for an example.
Figure 9.3. Auto-Complete Sug gestions from the VBA Ed itor
In this case the scrollable window gives you a list of all the things you can type af ter ActivePresentation. You can choose from the list by dou - ble-clicking on any item, or you can start typ ing. As you type, the window high - lights the first thing in the list (in al phabetical or der) that matches what you type. If noth ing is highlighted, you have typed something wrong. Gen erally, that list is all that is available to type. If the list of choices has gone away, you can de lete the line back to the dot; when you type the dot again, the list will come back.
In ad dition, in Windows the VBA Ed itor will make some sug gestions for pa ram e ters for pro ce dures. For ex am ple, if you type
activepresentation.slideshowwindow.view.gotoslide(
the VBA editor will give you some hints about what you can type next, specifi- cally what pa ram e ters theGotoSlide method wants (see Figure 9.4).
Fig ure 9.4. VBA Ed i tor Sug gests Pa ram e ters for theGotoSlide Method
The lit tle box has a lot of de tails that will help you. First, you can see that there are two pos si ble pa ram e ters sep a rated by com mas: In dex and ResetSlide. Although the box does not tell you what the parameters are for, it does tell you 166 De bug ging Tips
what kind of in formation they need. In this case, In dex is a Long vari able (that’s a kind of in teger). You can prob ably fig ure out that it is the slide num ber of the slide to go to. ResetSlide is an MsoTriState vari able (which is usu- ally just a True or False value).
You should also no tice that In dex is not in square brackets, but
ResetSlide is. This tells us that In dex is required andResetSlide is not. That is, you have to tellGotoSlide which slide to go to, but you don’t have to tell it whether or not to re set (the ResetSlide tells it whether or not to re set the animation ef fects on the slide; i.e., leave them in their fi nal state or put them back at the be ginning state). Also, no tice that ResetSlide has a de fault value. That is, if you don’t include a value for ResetSlide, it will as sume you wanted
msoTrue (which is ba sically the same as True), which means that the slide will be re set. Fi nally, you will notice that In dex is in bold. That means that the next thing I type will be the value used forIn dex. If I type a number and then a comma,ResetSlide will be come bold, meaning that the next value I type will be the value for ResetSlide. If you type pa rameters in or der, you can just type the values as in the following:
ActivePresentation.SlideShowWindow.View.GotoSlide(5,True)
If you don’t type them in order, you can use the parameter name, fol lowed by co - lon equals sign (:=), fol lowed by the value, as in the fol lowing:
ActivePresentation.SlideShowWindow.View.GotoSlide(ResetSlide:=True, _ In dex:=5)
This is very help ful for a cou ple of reasons. First, you don’t always have to look up which pa rameters are needed. For example, when add ing a shape, I can never re member which comes first and sec ond:Top and Left or Width and
Height. I don’t need to remember because VBA will tell me, as in Figure 9.5.
Fig ure 9.5. VBA Ed i tor Sug gests Pa ram e ters for theAddShape Method
Second, you al ways know what the procedure expects. If you leave off any re - quired parameters (such as forgetting to specifyWidth and Height), it won’t work.
VBA Help
While Win dows versions of the VBA Ed itor are better at sug gesting things as you type, Macintosh ver sions have help that is a bit easier to use. In ei ther ver- sion of VBA, you can choose one of the selections from the Help menu to search for a keyword. In the Macintosh ver sion, you can high light a key word, ob ject, or method in your code and hit the Help key on your keyboard. This will bring up help that is directly related to what you are trying to do.
When you are using help, you can get all the in formation that pops up on your screen when you type open parenthesis and VBA sug gests pa rameters. You should also check out the examples to help you un derstand what you are doing better.