How to Call a Function in VBA


Visual Basic for Applications is Microsoft’s event-driven programming language, which is associated with Visual Basic 6 and its Integrated Development Environment. VBA is widely used by many of Microsoft’s products and platforms, including Microsoft Office, specifically, Word and the Excel spreadsheet and data management program. The VBA language makes heavy use of functions, which are blocks of programming code and commands within VBA. To call a function in VBA, you must first configure the Office application to dislay the Developer tab.

  • Open Microsoft Word or Excel. Select File followed by Customize Ribbon. Click to enable the Developer check box in the Main Tabs section, and then click OK.

  • Click the Developers tab in the menu ribbon. Select Tools, Macro and click Visual Basic. You are now in the Visual Basic programming environment.

  • Go to the top menu bar and click Insert followed by Module.

  • Write the following code in the code Module:

    Function mymessagebox()

         MsgBox "Here is an example of how to call a function"

    End Function

  • Go to the top menu bar and click Insert, and then select UserForm.

  • Double-click the Userform and type the name of the function: mymessagebox. In the forms default click Event. The programming code should look like this:

    Private Sub UserForm_Click()

      call  mymessagebox

    End Sub

  • Press F5 on your keyboard to run the program. This will run the program and display a form dialog Window.

  • Click the Userform dialog Window. You should see a message box pop up in-front of the Userform Window with the words "Here is an example of how to call a function."

Related Searches


Promoted By Zergnet



You May Also Like

  • How to Nest a Sub in VBA

    Visual Basic programmers use nested subroutines, or nested subs, to isolate the execution of certain bits of code in their applications. A...

  • How to Call a Function in JavaScript

    Functions--named groups of statements that can be "called" or "invoked"--lie at the heart of JavaScript. Functions can be given special inputs, called...

  • How to Use a Subroutine in Excel Visual Basic

    Microsoft Excel's programming language, Visual Basic for Applications (VBA), is a powerful tool that is accessible to anyone, including non-programmers. With macros...

  • How to Call an SQL Stored Procedure Using MS Access VBA

    Knowing how to call a Microsoft SQL Server stored procedure from Microsoft Office Access using Visual Basic for Applications (VBA) can save...

  • Return Value of VBA Function

    Visual Basic applications, or VBAs, can be both simple and complex, depending on the software engineers involved and the needs for which...

  • Excel VBA Public Function

    The VBA "public" keyword exists to make VBA functions accessible to other VBA functions and subroutines. Specifically, it makes it possible for...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!