Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Passing Parameters to Functions.

Passing Parameters to Functions

by Allen Wyatt
(last updated September 7, 2016)


When you create your own functions, it is often helpful to pass parameters to the function. These parameters can be used either as data that you want the function to act upon or as settings used to control how the function does its work. How you pass parameters to functions is illustrated in the following macros:

Sub Macro1()
    A = 12.3456
    Status.Bar = A & "     " & Round(A)
End Sub
Function Round(X)
    Round = Int(X + 0.5)
End Function

This simple macro (Macro1) defines a number and assigns it to the variable A. It then prints that number and the result of passing the number to the Round function; the output is 12.3456 and 12. Notice that the parameter should be passed to the function within parentheses.

Also notice that the function does not use the same variable name as it was passed. (The variable A is passed to the function when it is invoked; within the function this value is referred to by the variable name X.) This is because VBA reassigns the value of X (what the function needs) so it matches the value of A (what the program is passing to the function).

VBA allows you to specify multiple parameters to be passed to a function. The parameters simply need to be separated by commas in both the declaration of the function and whenever the function is called. The important thing to remember in passing parameters to functions is that your program must pass the same number of parameters as the function expects, and the parameters must be of matching types and in the proper order.


If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12962) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Passing Parameters to Functions.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Getting Rid of Spaces in Cells

Importing data into Excel that was generated in other programs can have some interesting side effects. For instance, you ...

Discover More

Dealing with Oily Skin

Does your skin feel greasy to the touch and are you having problems getting just the right look with your facial makeup? ...

Discover More

Keyboard Control of the Find and Replace Dialog Box

Hate to take your hands off the keyboard? This tip explains how you can use the keyboard to work with the Find and ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Toggling Font Assignments in a Macro

If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This ...

Discover More

Clean Up Your Macro List

Macros are part of the document and template that are loaded into memory when you open a file. If you have "junk" macros ...

Discover More

Comparing Strings

When writing a macro, a common task is the need to compare two strings. You can do this by "normalizing" the strings, as ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 6?

2016-09-13 07:18:59


I understand the principle.
But about this specific instance it does not work
How can you really change the text in the status bar in Word 2013?

2016-09-07 16:02:20


Thanks to both Allen and Bryan. Bryan, I get why you've added your tips; you want us to do it right. And you have really good advice there. But Allen's initial tip was really helpful to me as a beginner. My issue is not about doing it right, it's about doing it at all. And the tip was simple enough that I can see a concept that I haven't really understood from other articles, see how I might actually get started. Between the two of you, well done!

2014-02-18 09:41:26


Bah, sorry about the Wall O' Text. I wrote it in Word in case my browser crashed, and forgot to add back in the extra line breaks.

2014-02-18 09:39:38


Couple of things here:

1) You can, and really, really should, dimension all of your variables. Instead of just "A = 12.3456", you should first have a line "Dim A as Double". (Option Explicit will avoid this error). You should also dimension variables within the function call: "Round(X As Double)". If you don’t, then you will be able to pass non-numbers into your Round function, thus causing an error. If X is dimensioned it’s a lot more likely that you will catch the error upon compiling instead of somewhere down the line. While you’re at it, you can also dimension the output: "Round(X As Double) As Double".
2) You can name the parameter when calling the function if you choose: "Status.Bar = A & " " & Round(X:=A)". Note the semicolon before the equals sign. If you use this technique, you no longer have to call the variables in the exact order. For instance, if you had a function defined as "Round(X as Double, Y as Double, Z as Double)" [terrible variable names, btw], you could call the function as "Round(Z:=1, Y:=2, X:=3)" and it would work exactly like you expect it to.
3) You also aren’t limited to only required variables. The Optional keyword allows you to make a parameter or parameters optional. These have to be last in the order of variables (in other words, you can’t have an optional parameter followed by a required parameter). Simply put, a function won’t throw up an error if you don’t put in the optional parameter. You can even give the parameter a default value. For instance, "Round(X as Double, Optional Y as Double, Optional Z as Double = -1)". If you called "Round(12.3456)", the function would still work. Y would default to 0 (the default for uninitialized Doubles), and Z would default to -1. You can also skip variables by leaving a comma, or by calling them out directly: "Round(12, , 34)", "Round(12, Z:=34)".
4) Lastly, you are not required to have a set number of inputs. If you don’t have any optional parameters, you can use the ParamArray keyword to make the last parameter a variant array that accepts any number of arguments. So You could declare a function "AddEmUp(ParamArray Nums())". Then you can call the function in the following ways: "AddEmUp()", "AddEmUp(1)", or "AddEmEup(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)".
5) The fifth thing (I guess I lied about the last one being the last one) is that if your function isn’t being used to return a value, you don’t need to use an equals sign, and you don’t need to use parenthesis. Reasons for having a function like this are nuanced; however, subroutines also accept parameters, and they never return a value, so you can choose to call your subroutines in this manner. Say you had a subroutine declared as "DeleteTheCells(RangeOfCells as Range)". You could call it as such: "DeleteTheCells Range("A1:A10")".

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.