How do I pass a Range to a Sub in Word VBA?
It is not allowed to call a Sub
with parenthesis, except if you are using the Call
statement.
Hence you have to use either:
Call ProcessRange(r)
Or:
ProcessRange r
The reason for that is that in VBA (and VBS, VB6, too) the parenthesis can have a whole lot of different meanings.
In your case the range object will be evaluated before passing the result to ProcessRange
. In this case it leads to a string
being passed to the sub, because the default property of Range
is Text
.
See this article for an overview: http://blogs.msdn.com/ericlippert/archive/2003/09/15/52996.aspx