Home Mathematics Chapter 5: VBA Procedures: Subroutines and Functions
Chapter
Licensed
Unlicensed Requires Authentication

Chapter 5: VBA Procedures: Subroutines and Functions

View more publications by Mercury Learning and Information
Earlier in this book you learned that a procedure is a group of instructions that allows you to accomplish specific tasks when your program runs. VBA has three types of procedures:Subroutine procedures (subroutines) perform some useful tasks but don’t return any values. Th ey begin with the keyword Sub and end with the keywords End Sub. Subroutines can be recorded with the macro re-corder (as you did in Chapter 1) or written from scratch in the Visual Basic Editor window (see Chapters 3 and 4). In Chapter 1, you learned various ways to execute this type of procedure.Function procedures (functions) perform specifi c tasks that return val-ues. Th ey begin with the keyword Function and end with the keywords End Function. In this chapter, you will create your fi rst function proce-dure. Function procedures can be executed from a subroutine or accessed from a worksheet just like any Excel built-in function.Property procedures are used with custom objects. With property pro-cedures you can set and get the value of an object’s property or set a ref-erence to an object. You will learn how to create custom objects and use property procedures in Chapter 9,"Working with Collections and Class Modules."Chapter5VBA PROCEDURES: SUBROUTINESANDFUNCTIONS153
© 2014 Walter de Gruyter GmbH, Berlin/Boston

Earlier in this book you learned that a procedure is a group of instructions that allows you to accomplish specific tasks when your program runs. VBA has three types of procedures:Subroutine procedures (subroutines) perform some useful tasks but don’t return any values. Th ey begin with the keyword Sub and end with the keywords End Sub. Subroutines can be recorded with the macro re-corder (as you did in Chapter 1) or written from scratch in the Visual Basic Editor window (see Chapters 3 and 4). In Chapter 1, you learned various ways to execute this type of procedure.Function procedures (functions) perform specifi c tasks that return val-ues. Th ey begin with the keyword Function and end with the keywords End Function. In this chapter, you will create your fi rst function proce-dure. Function procedures can be executed from a subroutine or accessed from a worksheet just like any Excel built-in function.Property procedures are used with custom objects. With property pro-cedures you can set and get the value of an object’s property or set a ref-erence to an object. You will learn how to create custom objects and use property procedures in Chapter 9,"Working with Collections and Class Modules."Chapter5VBA PROCEDURES: SUBROUTINESANDFUNCTIONS153
© 2014 Walter de Gruyter GmbH, Berlin/Boston

Chapters in this book

  1. Frontmatter i
  2. Contents vii
  3. Acknowledgments xxv
  4. Introduction xxvii
  5. Part I—Introduction to Excel 2013 VBA Programming
  6. Chapter 1: Automating Worksheet Tasks with Macros 1
  7. Chapter 2: Exploring the Visual Basic Editor (VBE) 47
  8. Chapter 3: Excel VBA Fundamentals 65
  9. Chapter 4: Using Variables, Data Types, and Constants 119
  10. Chapter 5: VBA Procedures: Subroutines and Functions 153
  11. Part II—Controlling Program Execution
  12. Chapter 6: Decision Making with VBA 195
  13. Chapter 7: Repeating Actions in VBA 221
  14. Part III—Keeping Track of Multiple Values
  15. Chapter 8: Working with Arrays 239
  16. Chapter 9: Working with Collections and Class Modules 277
  17. Part IV—Error Handling and Debugging
  18. Chapter 10: VBE Tools for Testing and Debugging 311
  19. Chapter 11: Conditional Compilation and Error Trapping 337
  20. Part V—Manipulating Files and Folders with VBA
  21. Chapter 12: File and Folder Manipulation with VBA 351
  22. Chapter 13: File and Folder Manipulation with Windows Script Host (WSH) 371
  23. Chapter 14: Using Low-Level File Access 397
  24. Part VI—Controlling Other Applications with VBA
  25. Chapter 15: Using Excel VBA to Interact with Other Applications 421
  26. Chapter 16: Using Excel with Microsoft Access 453
  27. Part VII—Enhancing the User Experience
  28. Chapter 17: Event-Driven Programming 507
  29. Chapter 18: Using Dialog Boxes 555
  30. Chapter 19: Creating Custom Forms 569
  31. Chapter 20: Formatting Worksheets with VBA 617
  32. Chapter 21: Context Menu Programming and Ribbon Customizations 671
  33. Part VIII—Programming Excel Special Features
  34. Chapter 22: Printing and Sending Email from Excel 737
  35. Chapter 23: Programming PivotTables and PivotCharts 771
  36. Chapter 24: Using and Programming Excel Tables 827
  37. Chapter 25: Programming Special Features 849
  38. Chapter 26: Programming the Visual Basic Editor (VBE) 865
  39. Part IX—Excel and Web Technologies
  40. Chapter 27: HTML Programming and Web Queries 911
  41. Chapter 28: Excel and Active Server Pages 939
  42. Chapter 29: Using XML in Excel 2013 977
  43. Part X Going Beyond the Limits of VBA
  44. Chapter 30: Calling Windows API Functions from VBA 1053
  45. Index 1081
Downloaded on 23.9.2025 from https://www.degruyterbrill.com/document/doi/10.1515/9781938549441-007/html?licenseType=restricted&srsltid=AfmBOoodTNdIUIpP11Jp77fvlDLiPv1ZF2mVrro9voKeiKGKHf8POjq9
Scroll to top button