Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

if statement not working!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yechiel - 06 Feb 2008 15:39 GMT
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?
Helmut Weber - 06 Feb 2008 15:48 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.