error when changing a paragraph style

K

keith brickey

My document has a paragraph style named "myData." When I select one
paragraph and run this subroutine:



For Each para In Selection.Paragraphs

para.Style = myData

Next para



I get the following error message:



"One of the values passed to this method or property is out of range,"

and the line:



para.Style = myData



is highlighted.


What am I doing wrong?
 
S

Stefan Blom

Put myData within double quotation marks, and it should work fine:

For Each para In Selection.Paragraphs
para.Style = "myData"
Next para

Without the quotes, Visual Basic for Applications thinks that myData
is a variable rather than a string value.
 
H

Helmut Weber

Hi Keith,
try
para.Style = "myData"
And besides that, if you select one (1) paragraph,
"for each" is useless. You don't even have to select
the paragraph at all, it is sufficient, if the insertion
point is in that paragraph.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
Top