if statement not working!

Y

Yechiel

I am trying to have a macro loop through the cells in a table (Word 2003),
and based on the shading color of the cells, either convert the text in the
cell to a nested table, or do nothing and go to the next cell.

Code:
dim <cellname> as cell

if <cellname>.shading.backgroundpatterncolor = wdColorGray05 or
wdColorGray15 then
<one set of actions, independently determined to work>
else
<other set of actions, independently determined to work>
end if

When I run the macro step-by-step, it always forks the same way regardless
of whether the condition was fulfilled or not. (I also tried AND instead of
OR, with the same result.)

All the rest of the code works fine - when I took out the if statement
above, it ran perfectly.

Any advice?
 
H

Helmut Weber

Hi Yechiel,

you are comparing a boolean
(<cellname>.shading.backgroundpatterncolor = wdColorGray05)
with the value of a constant (wdColorGray15) ...

try this:

if <cellname>.shading.backgroundpatterncolor = wdColorGray05 or
<cellname>.shading.backgroundpatterncolor = wdColorGray15 then

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
Top