This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Interpretation of the printing code: the rightmost double-digit number is the year of the book’s printing; the rightmost single-digit, the number of the book’s printing. For example, a printing code of 97-1 shows that the first printing of the book occurred in 1997. Composed in AGaramond and MCPdigital by Macmillan Computer Publishing
Acquisitions Editor Dean Miller
Development Editor Brian-Kent Proffitt
Software Development Specialists Patricia J. Brooks John Warriner
Production Editor Gayle L. Johnson
Copy Editor Bart Reed
Indexers Bruce Clingaman Erika Millen
Technical Reviewer John Charlesworth
Formatter Katie Wise
Technical Edit Coordinator
Printed in the United States of America
Lynette Quinn
Editorial Assistants
Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Carol Ackerman Andi Richter Rhonda Tinch-Mize
Cover Designer Jason Grisham
Book Designer Publisher and President Publishing Manager Director of Editorial Services Managing Editor Director of Marketing Assistant Marketing Managers
Richard K. Swadley Dean Miller Cindy Morrow Mary Inderstrodt Kelli S. Spencer Kristina Perry Rachel Wolfe
Gary Adair
Production Team Supervisors Brad Chinn Charlotte Clapp
Production Georgiana Briggs Shawn Ring Janet Seib Mary Ellen Stephenson
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Overview Introduction
iii
xxvi
Part I Unleashing the VBA Programming Language 1 Introducing VBA
3
2 Understanding Variables
39
3 Building VBA Expressions 4 Working with Objects
59
93
5 Controlling Your VBA Code
115
Part II Unleashing Microsoft Office Objects 6 Word for Windows VBA Programming
139
7 Manipulating Excel with VBA 171 8 Programming PowerPoint Presentations 217 9 VBA and Access
247
Part III Unleashing VBA User Interface Design 10 Interacting with the User
277
11 Working with Microsoft Forms 295 12 Creating Custom Menus and Toolbars
333
Part IV Unleashing Application Integration 13 Working with Other Applications
359
14 Programming OLE and ActiveX Objects
381
15 Controlling Applications Via OLE Automation 409 16 Rolling Your Own Objects with Class Modules
423
Part V Unleashing VBA Database Programming 17 Using VBA to Work with Excel Lists 445 18 Programming Data Access Objects
469
19 Advanced Database Programming
493
Part VI Unleashing VBA Internet and Intranet Programming 20 Internet and Intranet Programming Topics
535
21 Web Page Programming: ActiveX and VBScript
567
22 E-Mail and Groupware Programming with Outlook 603
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
iv
Visual Basic for Applications UNLEASHED
Part VII Unleashing Advanced VBA Programming 23 Trapping Program Errors 653 24 Debugging VBA Procedures
669
25 Programming the Windows API
689
26 VBA Tips and Techniques 727
Part VIII Unleashing VBA Applications 27 A Check Book Application 769 28 Making Backups as You Work
799
29 Access and Outlook: E-Mail Merge A VBA Statements
833
865
B VBA Functions 873 C The Windows ANSI Character Set 883 D An HTML Primer 891 Index
913
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
v
Contents Introduction
xxvi
Part I Unleashing the VBA Programming Language 1 Introducing VBA 3 What Is a Macro? ............................................................................. 4 How Does VBA Fit In? ............................................................... 4 The Three Types of Procedures ................................................... 5 Recording a VBA Macro .................................................................. 5 Viewing the Resulting Module .................................................... 7 Editing a Recorded Macro ........................................................... 8 Touring the Visual Basic Editor ....................................................... 8 The Project Explorer.................................................................... 8 The Properties Window ............................................................... 9 The Work Area .......................................................................... 10 Writing Your Own Command Macro ............................................ 11 Creating a New Module ............................................................ 11 Writing a Command Macro ...................................................... 12 Running a VBA Macro .................................................................. 13 Creating User-Defined Functions with VBA .................................. 13 Understanding User-Defined Functions .................................... 14 Writing User-Defined Functions ............................................... 16 Employing User-Defined Functions .......................................... 16 Working with Procedures ............................................................... 17 The Structure of a Procedure ..................................................... 17 Calling a Procedure ................................................................... 18 Public Versus Private Procedures ............................................... 20 Another Method for Inserting a Procedure ................................ 20 Visual Basic Editor Techniques for Easier Coding ..................... 21 Finding Code ............................................................................ 26 Navigating Modules with Bookmarks ........................................ 29 Working with Modules .................................................................. 30 Renaming a Module .................................................................. 30 Exporting a Module ................................................................... 30 Importing a Module .................................................................. 31 Removing a Module .................................................................. 32 Setting Visual Basic Editor Options ............................................... 32 The Editor Tab .......................................................................... 33 The Editor Format Tab ............................................................. 34 The General Tab ....................................................................... 34 The Docking Tab ...................................................................... 35
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
vi
Visual Basic for Applications UNLEASHED
Protecting Your Code..................................................................... 36 Summary........................................................................................ 37 2 Understanding Variables 39 Declaring Variables ........................................................................ 40 Understanding Variable Scope ....................................................... 42 Procedure-Level Scope ............................................................... 42 Module-Level Scope .................................................................. 44 Public Scope .............................................................................. 45 Passing Variables as Arguments ...................................................... 46 Passing Variables by Reference ................................................... 46 Passing Variables by Value ......................................................... 47 Working with Static Variables ........................................................ 48 Avoiding Variable Errors ................................................................ 49 Variable Data Types ....................................................................... 50 Changing the Default Data Type............................................... 52 Creating User-Defined Data Types ............................................ 53 Using Array Variables ..................................................................... 54 Dynamic Arrays ......................................................................... 55 Multidimensional Arrays ........................................................... 56 Working with Constants ................................................................ 57 Using Built-In Constants ........................................................... 57 Creating User-Defined Constants .............................................. 57 Summary........................................................................................ 58 3 Building VBA Expressions 59 Understanding Expression Structure .............................................. 60 VBA Operators .............................................................................. 61 Arithmetic Operators ................................................................. 62 The Concatenation Operator ..................................................... 62 Comparison Operators .............................................................. 63 Logical Operators ...................................................................... 65 Understanding Operator Precedence .............................................. 66 The Order of Precedence ........................................................... 66 Controlling the Order of Precedence ......................................... 67 Working with Numeric Expressions ............................................... 69 A Closer Look at the Arithmetic Operators ................................ 69 Numeric Data Type Conversion Functions ............................... 72 VBA’s Math Functions .............................................................. 73 VBA’s Financial Functions ........................................................ 75 Working with String Expressions ................................................... 77 Working with Logical Expressions.................................................. 80 The And Operator ...................................................................... 80 The Or Operator ........................................................................ 80
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
The Xor Operator ...................................................................... 80 The Eqv Operator ...................................................................... 81 The Imp Operator ...................................................................... 81 The Not Operator ...................................................................... 81 Working with Date Expressions ..................................................... 81 Formatting Numeric and Date Expressions .................................... 84 The Format Function ................................................................ 84 VBA’s Predefined Formats ......................................................... 85 User-Defined Numeric Formats ................................................ 87 User-Defined Date and Time Formats ....................................... 89 Summary ........................................................................................ 91 4 Working with Objects 93 What Is an Object? ......................................................................... 94 The Object Hierarchy .................................................................... 95 Working with Object Properties ..................................................... 96 Setting the Value of a Property .................................................. 97 Returning the Value of a Property ............................................. 98 Working with Object Methods ...................................................... 98 Handling Object Events ............................................................... 100 Working with Object Collections ................................................. 101 The Object Browser ..................................................................... 101 Object Browser Features .......................................................... 102 Working with the Object Browser ........................................... 103 Referencing Additional Object Libraries ....................................... 104 Assigning an Object to a Variable ................................................. 105 The Is Operator .......................................................................... 105 Working with Multiple Properties or Methods............................. 106 The Application Object ............................................................. 108 Properties of the Application Object ...................................... 108 Methods of the Application Object ....................................... 110 The Window Object .................................................................... 111 Specifying a Window Object ................................................... 112 Opening a New Window ......................................................... 112 Window Object Properties ...................................................... 112 Window Object Methods ........................................................ 113 Summary ...................................................................................... 113 5 Controlling Your VBA Code 115 Code That Makes Decisions ......................................................... 116 Using If...Then to Make True/False Decisions .......................... 116 Using If...Then...Else to Handle a False Result ...................... 118
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
vii
viii
Visual Basic for Applications UNLEASHED
Making Multiple Decisions .......................................................... 119 Using the And and Or Operators............................................... 119 Using Multiple If...Then...Else Statements ........................ 120 Using the Select Case Statement ........................................... 121 Functions That Make Decisions ................................................... 126 The IIf Function .................................................................... 126 The Choose Function .............................................................. 127 The Switch Function .............................................................. 128 Code That Loops ......................................................................... 129 Using Do...Loop Structures ......................................................... 130 Using For...Next Loops .............................................................. 131 Using For Each...Next Loops .................................................... 133 Using Exit For or Exit Do to Exit a Loop .................................. 134 Summary...................................................................................... 135
Part II Unleashing Microsoft Office Objects 6 Word for Windows VBA Programming 139 The Transition from WordBasic to VBA ..................................... 140 Reading and Setting Word’s Program Options Via VBA .............. 141 The View Tab ......................................................................... 142 The General Tab ..................................................................... 146 The Edit Tab ........................................................................... 148 Word’s Application Object ........................................................ 149 Properties of the Application Object ...................................... 149 Methods of the Application Object ....................................... 150 Working with Document Objects ................................................ 152 Specifying a Document Object ................................................ 152 Opening a Document .............................................................. 152 Creating a New Document ...................................................... 153 Document Object Properties ................................................... 153 Document Object Methods ..................................................... 154 Document Object Events ........................................................ 158 Objects That Represent Text in Word ......................................... 159 The Range Object ................................................................... 159 The Characters Object ........................................................... 162 The Words Object .................................................................... 163 The Sentences Object ............................................................. 164 The Paragraph Object.............................................................. 164 Checking Spelling and Grammar with VBA ................................. 166 Spell-Checking a Document or Range ..................................... 166 Spell-Checking a Word............................................................ 166
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
Checking Grammar ................................................................. 167 Word’s Spelling and Grammar Options .................................. 167 Summary...................................................................................... 169 7 Manipulating Excel with VBA 171 Excel’s Macro Options ................................................................. 172 Assigning a Shortcut Key ......................................................... 172 Recording with Relative References ......................................... 173 New VBA Features in Excel 97 .................................................... 174 Using VBA to Read and Set Excel’s Program Options .................. 175 The View Tab ......................................................................... 175 The Calculation Tab ............................................................... 177 The Edit Tab ........................................................................... 179 The General Tab ..................................................................... 180 Excel’s Application Object ......................................................... 181 Accessing Worksheet Functions ............................................... 182 Other Properties of the Application Object ........................... 182 Methods of Excel’s Application Object .................................. 183 Some Event-Like Methods ....................................................... 184 Manipulating Workbook Objects ................................................. 189 Specifying a Workbook Object ................................................ 189 Opening a Workbook .............................................................. 189 Creating a New Workbook ...................................................... 190 Workbook Object Properties ................................................... 191 Workbook Object Methods ..................................................... 191 Workbook Object Events ........................................................ 193 Dealing with Worksheet Objects .................................................. 195 Specifying a Worksheet Object ................................................ 195 Creating a New Worksheet ...................................................... 196 Properties of the Worksheet Object ......................................... 196 Methods of the Worksheet Object ........................................... 198 Worksheet Object Events ........................................................ 200 Working with Range Objects ....................................................... 202 Returning a Range Object ....................................................... 203 Using the Offset Method ....................................................... 206 Selecting a Cell or Range ......................................................... 208 Defining a Range Name .......................................................... 208 More Range Object Properties ................................................. 209 More Range Object Methods .................................................. 209 Working with Add-In Applications .............................................. 212 Creating an Add-In Application .............................................. 212 Controlling Add-Ins with VBA ................................................ 214 Summary...................................................................................... 215
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
ix
x
Visual Basic for Applications UNLEASHED
8 Programming PowerPoint Presentations 217 PowerPoint’s Application Object ............................................... 218 PowerPoint’s Presentation Object ................................................ 219 Specifying a Presentation Object.............................................. 219 Opening a Presentation ........................................................... 219 Creating a New Presentation ................................................... 220 Presentation Object Properties ................................................. 220 Presentation Object Methods .................................................. 221 The Juggling Application ......................................................... 222 Working with PowerPoint Slide Objects ...................................... 224 Specifying a Slide ..................................................................... 224 Creating a New Slide ............................................................... 225 Inserting Slides from a File ...................................................... 226 Slide Properties ........................................................................ 226 The Juggling Application: Creating the Slides .......................... 228 Slide Methods .......................................................................... 228 Dealing with Shape Objects ......................................................... 230 Specifying a Shape ................................................................... 230 Adding Shapes to a Slide .......................................................... 231 Some Shape Properties ............................................................. 234 The Juggling Application: Creating the Title Page ................... 237 Some Shape Methods .............................................................. 238 The Juggling Application: Creating the Instructions ................ 240 Operating a Slide Show ................................................................ 242 Slide Show Transitions ............................................................ 242 Slide Show Settings .................................................................. 243 Running the Slide Show .......................................................... 244 Summary...................................................................................... 245 9 VBA and Access 247 What’s New in Access 97 ............................................................. 249 The Access Object Hierarchy ....................................................... 250 Controlling Access Options .......................................................... 250 More About the Access Application Object ................................ 255 Some Application Object Properties ...................................... 255 Some Application Object Methods ........................................ 256 The Access Form Object .............................................................. 257 Opening a Form ...................................................................... 258 Creating a Form ...................................................................... 259 Closing a Form ........................................................................ 259 Form Object Properties ........................................................... 260 Form Object Methods ............................................................. 261
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
The Access Report Object ............................................................ 262 Opening a Report .................................................................... 262 Creating a Report .................................................................... 263 Closing a Report ...................................................................... 263 Report Grouping and Sorting .................................................. 264 The Control Object ..................................................................... 267 Using the Handy SysCmd Function ............................................... 268 Returning the Current State of an Object ................................ 268 Returning Information About Access ....................................... 268 Creating Access Event Handlers ................................................... 269 Working with Access Modules ..................................................... 271 Adding Code to the Form Module .......................................... 271 Adding Code to a Module Object............................................ 271 Protecting Access Projects ............................................................ 272 Summary ...................................................................................... 273
Part III Unleashing VBA User Interface Design 10 Interacting with the User 277 Programming Sounds ................................................................... 278 Beeping the Speaker ................................................................. 278 Programming PowerPoint Sound Effects ................................. 279 Displaying Information to the User .............................................. 280 Changing the Mouse Pointer in Access .................................... 280 Displaying a Message in the Status Bar .................................... 281 Displaying a Message Using MsgBox ......................................... 285 Getting Input from the User ........................................................ 289 Prompting the User for Input .................................................. 289 Accessing an Application’s Built-In Dialog Boxes .................... 291 Summary ...................................................................................... 292 11 Working with Microsoft Forms 295 Understanding Custom Forms and Dialog Boxes ......................... 296 Forms and Dialog Boxes in VBA 5.0 ....................................... 296 Adding a Form to Your Project .................................................... 297 Sharing Forms Between VBA Applications ................................... 298 Importing and Exporting Form Files ....................................... 298 Dragging Form Objects Between Applications ........................ 299 Changing the Form’s Design-Time Properties ............................. 299 The Appearance Category ........................................................ 300 The Behavior Category ............................................................ 300 The Font Category .................................................................. 300 The Misc Category .................................................................. 300 The Picture Category ............................................................... 301
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
xi
xii
Visual Basic for Applications UNLEASHED
The Position Category ............................................................. 302 The Scrolling Category ............................................................ 302 Working with Controls ................................................................ 302 Inserting Controls on a Form .................................................. 303 Selecting Controls.................................................................... 304 Sizing Controls ........................................................................ 304 Moving Controls ..................................................................... 306 Copying Controls .................................................................... 309 Deleting Controls .................................................................... 310 Grouping Controls .................................................................. 310 Ordering Overlapped Controls ................................................ 310 Setting Control Properties ....................................................... 311 Common Control Properties ................................................... 311 Setting the Tab Order ............................................................. 312 Adding Controls to the Toolbox .............................................. 313 Creating User-Defined Controls .............................................. 314 Handling Form Events ................................................................. 316 Types of Form Controls ............................................................... 317 Command Buttons .................................................................. 317 Labels ...................................................................................... 318 Text Boxes ............................................................................... 318 Frames ..................................................................................... 319 Option Buttons ....................................................................... 320 Check Boxes ............................................................................ 320 Toggle Buttons ........................................................................ 320 List Boxes ................................................................................ 320 Scroll Bars................................................................................ 322 Spin Buttons ............................................................................ 322 Tab Strips and MultiPage Controls ......................................... 323 Using a Form in a Procedure ........................................................ 327 Displaying the Form ................................................................ 327 Handling Events While the Form Is Displayed ........................ 328 Unloading the Form ................................................................ 329 Processing the Form Results .................................................... 330 Summary...................................................................................... 332 12 Creating Custom Menus and Toolbars 333 Assigning Macros to Menu Commands ........................................ 334 First, a Game Plan ................................................................... 335 Creating a New Menu ............................................................. 335 Creating a New Cascade Menu ................................................ 337 Adding Menu Commands and Assigning Macros .................... 337 Deleting Menus and Menu Commands ................................... 338
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
Creating Custom Toolbars for Your Macros ................................ 338 Creating a New Toolbar .......................................................... 339 Adding a Toolbar Button and Assigning a Macro .................... 339 Menus, Toolbars, and VBA 5.0 .................................................... 340 Understanding Command Bars .................................................... 341 Specifying a Command Bar ..................................................... 341 Properties of the CommandBars Object ...................................... 343 Working with Command Bars ..................................................... 344 Creating a New Command Bar ............................................... 344 Command Bar Properties ........................................................ 345 Deleting a Custom Command Bar .......................................... 347 Resetting a Built-In Command Bar ......................................... 348 Working with Command Bar Controls ........................................ 348 Specifying a Control ................................................................ 349 Adding a Control to a Command Bar ...................................... 350 The Command Bar Info Utility ............................................... 351 Control Properties ................................................................... 351 Control Methods ..................................................................... 354 Summary ...................................................................................... 356
Part IV Unleashing Application Integration 13 Working with Other Applications 359 Starting Another Application ....................................................... 360 Activating a Running Application ................................................ 363 Sending Keystrokes to an Application .......................................... 365 Using Dynamic Data Exchange .................................................... 369 DDE: The Basics ..................................................................... 369 Initiating a Link Between VBA and a Server Application ......... 370 Controlling the Server Application .......................................... 373 Exchanging Data with the Server Application .......................... 374 Summary ...................................................................................... 378 14 Programming OLE and ActiveX Objects 381 First, Some OLE Fundamentals ................................................... 382 Compound Documents ........................................................... 383 The Component Object Model ............................................... 388 OLE Automation .................................................................... 390 ActiveX Controls ..................................................................... 390 OLE and the Registry ................................................................... 391 Programmatic Identifier Keys .................................................. 391 CLSID Keys .............................................................................. 393 Programming Linked and Embedded Objects .............................. 394
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
xiii
xiv
Visual Basic for Applications UNLEASHED
Inserting OLE Objects ................................................................. 394 Understanding the AddOLEObject Method .............................. 395 Looking Up an Object’s Class Type......................................... 396 Inserting a New Embedded Object .......................................... 398 Inserting an Existing File as an Embedded Object ................... 399 Inserting an Existing File as a Linked Object ........................... 400 OLE Objects and Word’s InlineShape Object ......................... 401 Inserting ActiveX Controls in Word ........................................ 402 Working with Linked and Embedded Objects ............................. 402 Some OLE Object Properties .................................................. 403 Some OLE Object Methods .................................................... 404 Summary...................................................................................... 407 15 Controlling Applications Via OLE Automation 409 Understanding Automation .......................................................... 411 Referencing Object Libraries.................................................... 411 Late Binding Versus Early Binding .......................................... 413 Accessing Automation Objects ..................................................... 414 The New Keyword .................................................................... 414 The CreateObject Function ................................................... 416 The GetObject Function ......................................................... 418 Handling Automation Errors ....................................................... 419 Summary...................................................................................... 421 16 Rolling Your Own Objects with Class Modules 423 Partway There: Custom Collections ............................................. 424 Declaring a Custom Collection ................................................ 425 Adding Objects to a Custom Collection .................................. 425 Working with Objects in a Custom Collection ........................ 427 Removing Objects from a Custom Collection ......................... 428 Understanding Class Modules ...................................................... 428 Setting Up a Class Module ........................................................... 430 Creating the Class Module ...................................................... 430 Defining the Data Members .................................................... 431 Implementing Class Properties ..................................................... 432 The Property Get Procedure .................................................. 432 The Property Let Procedure .................................................. 433 Setting Up the Class Methods ...................................................... 435 Defining the Class Events ............................................................. 435 The Initialize Event ............................................................ 436 The Terminate Event .............................................................. 436 Creating Class Collections ............................................................ 436 Setting Up a Class Module for a Collection ............................. 437 Providing Wrappers for Each Member .................................... 437
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
Implementing Class Properties for Objects ................................... 439 Using Events with the Excel Application Object ........................ 440 Summary ...................................................................................... 441
Part V Unleashing VBA Database Programming 17 Using VBA to Work with Excel Lists 445 What Is a List? ............................................................................. 446 Working with List Data ............................................................... 447 Setting Up the Application ........................................................... 449 Entering Data .............................................................................. 452 Entering Data Using a Custom Form ...................................... 453 Handling Data Entry with VBA .............................................. 453 Preparing the Data Entry Form ............................................... 454 Writing Data to the Database .................................................. 456 Editing Data ................................................................................ 458 Editing Data Using the Custom Form ..................................... 458 Handling Data Editing with VBA Code .................................. 459 Filtering Data ............................................................................... 461 Filtering the Customer Database ............................................. 461 Filtering Data with VBA .......................................................... 462 Autofiltering a Worksheet ........................................................ 463 Getting a Count of the Database Records .................................... 464 Deleting Records .......................................................................... 465 Deleting a Customer Database Record .................................... 465 Handling Record Deletion with VBA ...................................... 465 Sorting Data ................................................................................. 466 Subtotaling Data .......................................................................... 467 Summary ...................................................................................... 468 18 Programming Data Access Objects 469 About Data Access Objects........................................................... 470 Accessing Data in an External Database ....................................... 472 Creating a Workspace .............................................................. 473 Connecting to a Jet Database ................................................... 473 Connecting to a Non-Jet Database .......................................... 476 Connecting to an ODBC Data Source .................................... 479 Working with Recordsets ............................................................. 480 Understanding the Recordset Types ........................................ 480 Getting Field Information ....................................................... 481 Recordset Properties ................................................................ 482 Recordset Methods .................................................................. 484
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
xv
xvi
Visual Basic for Applications UNLEASHED
Querying a Recordset ................................................................... 485 Opening a Recordset Using a SQL Expression ......................... 486 Opening a Recordset from a QueryDef Object ........................ 486 Retrieving Data into Excel ........................................................... 487 Retrieving an Individual Field Value........................................ 488 Retrieving One or More Entire Rows ...................................... 488 Retrieving an Entire Recordset................................................. 489 Summary...................................................................................... 490 19 Advanced Database Programming 493 Maintaining a Jet Database .......................................................... 494 Creating a New Database ........................................................ 494 Compacting a Database ........................................................... 498 Repairing a Database ............................................................... 503 Replicating a Database ............................................................. 505 Working with Transaction Processing .......................................... 509 Using the ODBCDirect Workspace ............................................. 511 Creating an ODBCDirect Workspace ..................................... 512 Connecting to a Database ........................................................ 513 Working with ODBCDirect Recordsets .................................. 516 Returning Multiple Recordset Objects ..................................... 517 Programming Jet Database Security ............................................. 518 Creating a Secure Database ...................................................... 519 Opening a Secure Database ..................................................... 523 Working with the User Object ................................................ 524 Working with the Group Object ............................................. 526 Setting Object Permissions ...................................................... 529 Summary...................................................................................... 532
Part VI Unleashing VBA Internet and Intranet Programming 20 Internet and Intranet Programming Topics 535 Controlling Office 97 Hyperlinks ................................................ 537 Working with the Hyperlink Object ........................................ 538 The FollowHyperlink Method ................................................ 541 Building a Custom Web Browser ................................................. 542 Referencing the WebBrowser Control ..................................... 543 Displaying Web Pages with the WebBrowser Control ............. 544 Application: The World Wide Web Browser ........................... 545 Navigating with the WebBrowser Control ............................... 548 Navigating in the World Wide Web Browser .......................... 549 Controlling Internet Explorer Via Automation ............................ 551 Setting References and Object Variables .................................. 552 Internet Explorer Properties ..................................................... 552
P3/V4/swg1 VBA Unleashed #31046-5 janet 2/27/97 FM Lp#3
Contents
Controlling Netscape Navigator Via Automation ......................... 554 Connecting to Navigator ......................................................... 554 Methods of the Netscape.Network.1 Object ........................... 554 Application: The Navigator Automator ................................... 556 Summary ...................................................................................... 564 21 Web Page Programming: ActiveX and VBScript 567 ActiveX: The