Welcome toWord.Tips.Net
Ask a Word Question
Make a Comment
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Printing On Both Sides of the Paper
Turning Off AutoComplete for Dates
Understanding Auto Line Spacing
Adding Comments to Your Document
Conditional Calculations in Word
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
Great Idea! Word is a tool to get what you really want—printed output. This means you need to make sure that Word works as well as possible with your printer, whether it is sitting on your desk or in a room down the hall.