Going On from Here


In this chapter, you've learned how to create macros with the help of the macro recorder. As you learn more about VBA, you'll notice that the macro recorder often creates more code for a task than you really need. In our CompanyFont macro, for example, the following lines that the recorder generated were unnecessary because all you wanted to do was set the font name, point size, and style:

 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ThemeColor = xlThemeColorLightl .TintAndShade = 0 .ThemeFont = xlThemeFontMajor 

The recorder added these lines because it didn't (and couldn't) know they weren't necessary. You can remove them without changing the functionality of the macro.

Earlier in the chapter, you saw that it is possible, using VBA, to change an object's property settings (a cell's font formats, for example) without selecting the object. Nevertheless, the recorder always selects objects before taking actions that affect those objects. It does so because it must mimic everything you do when you create the recording. As you acquire more proficiency with VBA, you'll learn ways to edit the recorder's code to make it more efficient.

As you improve your expertise in VBA, you will probably find yourself creating most of your code directly in the Visual Basic Editor, bypassing the recorder altogether. Chances are, though, you'll still return to the recorder now and then. The Excel object model includes so many objects, methods, properties, and arguments that it's difficult-perhaps pointless-to try to remember them all. When you can't remember what property, object, or method is required in a certain programming situation, one of the easiest ways to get the information you need is by turning on the macro recorder, working through by hand the actions you want to program, and then seeing what code the recorder generates.



Microsoft Office Excel 2007 Inside Out
MicrosoftВ® Office ExcelВ® 2007 Inside Out (Inside Out (Microsoft))
ISBN: 073562321X
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net