Page 751 - Excel 2013 All-in-One For Dummies
P. 751

Using the Visual Basic Editor 733
    Why not simply type in the arguments of the InputBox function?
The biggest reason for using the variables InputMsg, InputTitle, and DefaultText to supply the prompt, title, and default arguments of the InputBox function — rather than just typing them into the function — is their length. If you typed in all three pieces of text within the parentheses of the InputBox function, you would end up with one of the longest (and hardest to read) lines of code in history. When
you use variables to do the job, as in the exam- ple shown previously, you end up with lines of code that fit on one screen, thus making the lines of code easier to read and also making it possible to print them on a normal piece of paper. If you use the variables on other proce- dures in the macro, declaring them all together at the beginning of the code also makes it easy to update their values.
  Figure 2-5:
The Spreadsheet Title dialog box that appears when you run the Company_ Name macro.
  Writing new macros in the Visual Basic Editor
After you have the skill in the VBA language, you can write new macros from scratch in the Visual Basic Editor instead of just editing ones that you’ve previously recorded in your spreadsheet by using Excel’s macro recorder. When creating a macro from scratch in the Visual Basic Editor, you need to follow these general steps:
1. Click the name of the VBA project in the Project Explorer window where you want to add the new macro.
If you want to write a macro just for the current workbook, click the VBAProject function that contains its filename in parentheses, as in VBAProject (My Spreadsheet). If you want to write a global macro in the Personal Macro Workbook, click VBAProject(PERSONAL.XLSB) in the Project Explorer window.
 Book VIII Chapter 2
 VBA Programming























































































   749   750   751   752   753