Installing and Using the Practice Files

The companion CD contains practice files that you can reference as you perform the exercises in the book. By using these practice files, you won't need to spend time creating the samples used in the chapters—instead, you can concentrate on learning how to become proficient at using Visual Basic for Applications in Office. With the files and the samples in the chapters, you'll also learn by doing, which is an easy and effective way to acquire and remember new skills.

Installing the Practice Files on Your Computer

To install the practice files on your computer's hard disk so that you can use them with the exercises in this book, complete the following steps:

  1. Insert the companion CD into your CD-ROM drive.
  2. On the taskbar at the bottom of your screen, click the Start button, and then click Run.
  3. The Run dialog box appears.

  4. In the Open box, type d:setup (if your CD-ROM drive uses a drive letter other than "d," substitute the correct drive letter).
  5. Click OK, and then follow the directions on the screen.
  6. The setup program window appears with recommended options preselected for you. For best results using the practice files with this book, accept these preselected settings.

  7. After the files have been installed, remove the CD from your drive and replace it in the package inside the back cover of the book.
  8. A folder called Office VBA Fundamentals has been created on your hard disk, and the practice files have been placed in that folder.

Using the Practice Files

Each chapter in this book explains when and how to use any practice files for that chapter. When it's time to use a practice file, the book will give you instructions on how to open it. You should always save the practice file with a new name (as directed in the chapter). That way the original practice file will be available if you want to go back and redo any of the chapters.

Here's a list of the practice files included on the practice CD, along with where each file is used:

Chapter Filename Description
2 Basics.ppt Reveals the fundamentals of the Visual Basic programming language.
3 UserForm.xls Provides a set of custom UserForms showing the use of buttons, list boxes, drop-down lists, and other common controls in dialog boxes.
frmBasic.frm, frmAsst.frm, frmSubwy.frm, FullWizd.frm Each file provides a UserForm template for the different stages of creating an Office wizard.
modAsst.bas, Assistnt.bmp Contains code to display tips in the Assistant balloon, as well as to close it when necessary. The code is reusable in any Office application. The file Assistnt.bmp is a bitmap file you can use on a button on a custom dialog box. The button gives your users a way to display the Office Assistant and access help for your solution.
modBrwse.bas, modFlDlg.bas Show how to use Windows application programming interfaces (APIs) to display the Browse for Folder and File dialog boxes provided by the Windows operating system.
4 DocMgtWd.bas, DocMgtXl.bas, DocMgtPp.bas Show how to use the Add and Open methods on the Documents, Workbooks, and Presentations collection objects to create and open documents. They also show how to use the Print, Close, SaveAs, and related save methods in Word, Excel, and PowerPoint.
FileMgmt.bas Contains code that uses built-in functions in the Visual Basic for Applications language to parse filenames. The code also tells you how to display Windows system dialog boxes that allow the user to specify a file or folder.
FileSys.bas Contains code that uses the Microsoft Scripting Runtime object library, which provides objects, methods, and properties you can use to access the file system where your program is executed. Before you use this code in your program, you need to reference the Microsoft Scripting Runtime object library in the References dialog box of your Visual Basic development environment.
OutlItem.bas Contains code to create an Outlook e-mail item from any Office application.
SHGetFdr.bas This module contains the definition of the Windows application programming interface (API) named SHGetSpecialFolderLocation, which is used to get folders like the Desktop, Application Data, and Favorites on the user's machine.
ShellExc.bas Shows how to use the ShellExecute Windows application programming interface (API) to load or print any file or load an application on your machine. The ShellExecute API is used to display a Web page saved from Word, Excel, or PowerPoint in the Web browser installed on your machine.
5 WdEvents.cls, WdInit.bas, XlEvents.cls, XlInit.bas, PpEvents.cls, PpInit.bas The combination of the two files for Word, Excel, and PowerPoint shows the event procedures that are called in your programs when any one of the following commands or their programmatic equivalents (as described in Chapter 4) are invoked through the File menu or through Visual Basic code: New, Open, Close, Save, Save As, Save as Web Page, and Print.
6 WdContnt.bas, XlContnt.bas, PpContnt.bas Show how to insert content such as text, tables, shapes, and cell values and how to manipulate content, including text and shape formatting. You can use the code to search for specific content in a document.
7 CreatePP.doc Creates a PowerPoint presentation from the headings in a Word document.
AppObjs.bas The procedures in this standard code module create instances of Office applications using the CreateObject and GetObject functions and the New keyword that is built into the Visual Basic for Applications language.
8 Energy.mdb This Access database file contains data used to automatically generate a Word document based on a prebuilt template (EnerRpt.dot), an Excel workbook, a PowerPoint presentation, and an Outlook e-mail message.
LabEnerg.txt A text file containing data generated by a hypothetical digital meter connected to a computer.
EnerRpt.dot A template that determines what the report that Energy.mdb creates will look like.
9 WdSelect.bas, XlSelect.bas, PpSelect.bas, OlSelect.bas Provides the code required to develop programs that need to retrieve, set, or act upon the active document or current selection.
10 WdEvents.cls, WdInit.bas, XlEvents.cls, XlInit.bas, PpEvents.cls, PpInit.bas The combination of the two files for Word, Excel, and PowerPoint shows the event procedures that are called in your programs when the user changes the selection of content or double-clicks or right-clicks any content item.
WndMenu2.xls Shows how you can use a combination of events, such as window activate, window deactivate, and command bar control clicks to build your own custom window menu similar to the Windows menu in Word, Excel, and PowerPoint.
OlEvents.cls, frmPreview.frm Provide code that allows you to display a modeless custom dialog box that displays the body text of the first item in a selection of items in your Outlook Mailbox. The behavior of the custom dialog box mimics the behavior of the Preview Pane in Outlook.
11 CmdBars.bas, Class1.cls Contains Visual Basic code to customize, add, or delete menu commands and toolbars in any Office application.
TgglEvnt.cls This class module provides an event procedure that reveals how to toggle the up-down state and caption of a menu item or toolbar button.
CmboCtrl.bas, ChngEvnt.cls CmboCtrl.bas shows you how to create a combo box drop-down list similar to the built-in Zoom control on the Standard toolbar in Word, Excel, and PowerPoint. ChngEvnt.cls shows you how to write code in the Change event of a combo box control that determines if a numerical value along with a percent sign is entered in the combo box. The code in the event procedure allows you to add a custom combo box control that mimics the behavior of the Zoom control.
DropCtrl.bas, DropEvnt.cls The combination of the standard code module and the class module shows how to add a drop-down list control and determine which item is selected in the list.
ChngMPtr.bas, ChngMPtr.cls The combination of the two files shows how to use the Windows application programming interfaces (APIs) LoadCursor and SetCursor to change the mouse pointer to an hourglass (or wait) cursor. The toolbar button Click event procedure also uses the Windows API Sleep to delay the execution of code.
FindCtrl.bas Contains code that uses the new FindControls method on the CommandBars collection object. The FindControls method allows you to write code that searches for a specific control and returns a subcollection of all the controls in the command bar set that match the search criteria.
12 FileSrch.xls Displays a custom file search UserForm to search for specified files on your system.
modMenu.bas Reusable code to add or remove menu items in any Office application.
modAssnt.bas Reusable code that allows you to create custom Office Assistant balloons. The samples show you how to create balloons with formatted text such as bold, underlined, and colored. The code also shows how to add check boxes and labels and to specify the buttons to be displayed in the Assistant's balloon.
13 BascAddn.vbp, CnntWord.Dsr, CnntExcl.Dsr, WrdEvnts.cls, XclEvnts.cls, Dialog.frm, CmbInit.bas, CmbEvnts.cls The Visual Basic 6.0 project, BascAddn.vbp, provides the basics for creating a COM add-in for any Office 2000 application. The project files CnntWord.dsr and CnntExcl.dsr allow the add-in to target Word and Excel. The remaining class module files, along with the standard code module files, show how to set up an Office application event procedure and a command bar control event procedure in a COM add-in. You use the project file Dialog.frm to show how a Visual Basic 6.0 form can be displayed in an Office application.
14 AppStart The Visual Basic 6.0 project in this subfolder provides the code in a COM add-in that is used to determine how an Office application was started. For example, was the application started by a user through the Windows Start menu? Or was it started through Automation code using the CreateObject function built into the Visual Basic for Applications language?
AutoList The Visual Basic 6.0 project in this subfolder references each of the Office 2000 applications for which the COM add-in is targeted in order to take advantage of the Auto List Members feature in Visual Basic while writing code.
Commncte The two Visual Basic 6.0 projects in this subfolder provide the code that enables one COM add-in to communicate with another. The first COM add-in communicates with the second through the use of the COMAddIn object defined in the Office 9.0 Object Library.
Distngsh The Visual Basic 6.0 project in this subfolder provides the code used to tell which application has loaded the COM add-in. If you develop a COM add-in that's loaded in more than one Office application, you'll often need to write code that is specific to one application. There- fore, by using the Name property on the Appli- cation object in each Office application, you can write Select Case statements to determine the application that the COM add-in is loaded into.
DmndLoad The Visual Basic 6.0 project in this subfolder provides the code used to create a COM add-in that is loaded on demand. You can create a COM add-in that needs to be loaded only after a user clicks on a specific menu item, toolbar button, or combo box.
NoDsgnr The Visual Basic 6.0 project in this subfolder shows you how to develop a COM add-in that doesn't use the add-in designer. Instead, it uses a class module in Visual Basic that implements the IDTExtensibility2 interface. This project also requires you to use a Windows Registry file with the file extension .reg to register your COM add-in.

Uninstalling the Practice Files

Use the following steps to delete the practice files that the Setup program added to your hard disk:

  1. Click the Start button, point to Settings, and then click Control Panel.
  2. Double-click the Add/Remove Programs icon.
  3. Select Microsoft Office 2000 Visual Basic for Applications Fundamentals from the list, and then click Add/Remove.
  4. Click Yes when the confirmation message appears.
  5. The practice files are uninstalled.

  6. Click OK to close the Add/Remove Programs Properties dialog box.
  7. Close the Control Panel window.