eg Selection... instead of ...How do you find out about objects, properties and methods?record a macro, then highlight a method or property name & press the help keyie if you see something and wonder about ituse the “object browser”if you want to go looking to see, for example, if worksheets have a particular property31Sub Sort_By_Mark2()Range("B3:D14").SelectSelection.Sort _Key1 := Range("D3"), _Order1 := xlDescending, _Header := xlGuess, _OrderCustom := 1, _MatchCase := False, _Orientation := xlTopToBottomRange("A1").SelectEnd SubCS 200 Spring 2018Excel ScriptingThe Object BrowserClick in the “Classes” or “Members” liststype to scroll their contents automaticallyclick on ? to open the help window on that object or memberthis is the best way to discover what members a class hasNB: “Excel” is selected in the pull-down top left32
CS 200 Spring 2018Excel ScriptingOnline Help for the Range Method33You can also access help for a property or method by•highlighting it in a macro module and pressing the help keyHints for the assignment!•The “Remarks” info about Ranges may be usefulWarning: Excel and VB havedifferent Help databases.CS 200 Spring 2018Excel Scripting34This dot marks a “breakpoint”Watching Your Macros Run
CS 200 Spring 2018Excel Scripting35Debugging (The Big Picture)CS 200 Spring 2018Excel ScriptingUsing the Debugger36Set a breakpointby clicking in the left marginto halt a macro when it gets to that statement“clear” the breakpoint by clicking again in the left marginUse? variableName <return> in the Immediate Window to display the value of the variableUseDebug > Step Into(doesdive into functions or subroutines)Debug > Step Over(doesn’tdive into functions or subroutines)to execute one statement and stop againUseRun > Continueto turn the macro looseThe Visual Basic Editor’s Debug toolbar has buttons for all of these(View > Toolbars... > Debug)
CS 200 Spring 2018Excel ScriptingTorun a macrodelete a macroedit a macroAnd via the Options... buttonyou can attach a macro to a key(or key combination) on the keyboard 37Putting It Together: Tools > Macro > Macros...CS 200 Spring 2018Excel ScriptingAttaching a Macro to a Spreadsheet ButtonDraw a button after selecting on the Forms toolbarCtrl-click on the button to open the Assign Macro dialogSelect and OK the desired macro38
CS 200 Spring 2018Excel ScriptingRecord•to learn how to do something•to build a macro fasterEdit recorded macros to customize / elaborate themUse on-line help and the object browserto find object names, properties, & methods that you needExperiment•with toy macros & documents•eg the workbooks used in lecture (see Learn Week 6: Application Scripting (Excel) / Files For Excel Scripting)Use the debugger•to understand what your macros are doing!Save everything you do, and include comments (they start with the single quote character ')39Strategies For Working With MacrosCS 200 Spring 2018Excel ScriptingThe Assignment For This Week40Given the raw data, duplicate the functionality of this spreadsheet