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 / November 2004

Tip: Looking for answers? Try searching our database.

tables using visual basic

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dhickey - 02 Nov 2004 21:55 GMT
I have a document and it has multiple tables with shading.  The shadin
ranges from 20-35 percent.  I am using WORD97.  How can I do
edit/replace in VB to find all the shading and replace it with 10%.

Please help

Debbi

--
Message posted from http://www.ExcelForum.com
Klaus Linke - 03 Nov 2004 12:24 GMT
> I have a document and it has multiple tables with shading.
> The shading ranges from 20-35 percent.  I am using WORD97.
> How can I do a edit/replace in VB to find all the shading and
> replace it with 10%.

Hi Debbie,

Edit > Replace doesn't work for this.
You'd loop through all cells in all tables, and set the shading to 10% if
it is currently 20-35 percent.

If you want to apply 10% shading to all cells that currently have any
shading at all (other than "automatic" = none):

Dim myTable As Table
Dim myCell As Cell
For Each myTable In ActiveDocument.Tables
 For Each myCell In myTable.Range.Cells
   With myCell.Shading
     If .BackgroundPatternColor <> _
       wdColorAutomatic Then
       .BackgroundPatternColor = wdColorGray10
     End If
   End With
 Next myCell
Next myTable

I'm not sure if Word97 used RGB colors, or if it used textures. If the
latter, you would write something like
     If .Texture <> wdTextureNone Then
       .Texture = wdTexture10Percent
     End If
in the inner loop.

Regards,
Klaus
dhickey - 04 Nov 2004 18:46 GMT
thank you very much it worked perfect

--
Message posted from http://www.ExcelForum.com
dhickey - 16 Nov 2004 19:13 GMT
Klaus that visual basic code worked for my tables except for when the
shading is using a pattern style instead of a fill.  What would I add
to the code.

Debbie

---
Message posted from http://www.ExcelForum.com/
Klaus Linke - 17 Nov 2004 11:41 GMT
> Klaus that visual basic code worked for my tables except for when
> the shading is using a pattern style instead of a fill.  What would I add
> to the code.
>
> Debbie

Hi Debbie,

If you want to replace any pattern with 10% gray shading, the macro below
should hopefully work.
If you only want to replace the shading in some tables, select them and
replace "ActiveDocument.Tables" with "Selection.Tables" in the macro.

Regards,
Klaus

 Dim myTable As Table
 Dim myCell As Cell
 For Each myTable In ActiveDocument.Tables
   For Each myCell In myTable.Range.Cells
     With myCell.Shading
       If .Texture <> wdTextureNone Then
         .Texture = wdTextureNone
         .BackgroundPatternColor = wdColorGray10
       End If
     End With
   Next myCell
 Next myTable

Regards,
Klaus
dhickey - 18 Nov 2004 14:43 GMT
klaus that worked for both.  You are great.  thanks.  debbi

--
Message posted from http://www.ExcelForum.com
dhickey - 18 Nov 2004 20:03 GMT
What is happening is on the new code you sent me that works if it has
pattern but it does not work on the fill.  The first one you gave m
worked on the fill.  It does not work for both.  Any ideas

--
Message posted from http://www.ExcelForum.com
Klaus Linke - 24 Nov 2004 15:04 GMT
Run both macros... Or put all the code in one macro.

Regards,
Klaus

> What is happening is on the new code you sent me that works if it
> has a pattern but it does not work on the fill.  The first one you
> gave me worked on the fill.  It does not work for both.  Any ideas.
 
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.