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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top