Welcome toWord.Tips.Net
Ask a Word Question
Make a Comment
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Standardizing Note Reference Placement
Selecting Printing of Color Pictures
You already know that you can use subroutines in your macros. VBA allows you to define functions that can be used in your macros. The difference between functions and subroutines is that functions can return values, whereas subroutines cannot. Consider the following VBA macros:
Sub Macro1()
TooMany = TestFunc
If TooMany Then StatusBar = "Too many pages"
End Sub
Function TestFunc()
TestFunc = False
If Selection.Inforamtion(wdNumberOfPagesInDocument) > 10 Then
TestFunc = True
End If
End Function
This function returns either the value True or False, depending on a test it performs. The main program then acts upon the value returned. Notice that the function name can appear on the right side of an equal sign. This makes functions very powerful and an important part of any program. Within the function the result is assigned to TestFunc, which is the name of the function itself; this is the value returned by the function.
Tip #1535 applies to Microsoft Word versions: 97 2000 2002 2003
Create and Merge! Using Word's mail merge tool you can quickly and easily combine data from a variety of data sources to create great individualized documents that incorporate your data in ways that you control. WordTips: Mail Merge Magic is an invaluable source for learning how to harness the full power of Word's mail merging capabilities.