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 / March 2006

Tip: Looking for answers? Try searching our database.

Find-object - Unable to replace background color formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Marti Menzel - 28 Feb 2006 12:49 GMT
Hello,

I've been asked to transfer the contents of a batch of Word-documents to
a new format. The problem is that they don't use templates for either of
them (source nor destination), but direct formatting (arghhh!) instead.

So I'm transferring the contents from the MainTextStory from one batch
to the other and applying format replacements to the destination files.
I know, this is not the most elegant way to do it, but that is what my
colleagues want.

I have a problem with the following replacement piece of code, that
among other things replaces a black paragraph background with an
outlined textured background.

With myRange.Find
   'El estilo no sirve, porque no es consistente (Titulo 2, Titulo 3)
   .Text = ""
   .Format = True
   .Font.Name = "Arial"
   .Font.Size = 12
   .Font.Color = wdColorWhite
   .Font.Italic = True
   .Replacement.Style = "Normal"
   .Replacement.Font.Name = "Arial Narrow"
   .Replacement.Font.Size = 10
   .Replacement.Font.Bold = True
   .Replacement.Font.Color = wdColorAutomatic
   .Replacement.ParagraphFormat.Alignment = wdAlignParagraphJustify
   .Replacement.ParagraphFormat.Borders.OutsideLineStyle =
wdLineStyleSingle
   .Replacement.ParagraphFormat.Borders.OutsideLineWidth = wdLineWidth050pt
   .Replacement.ParagraphFormat.Borders.OutsideColor = wdColorBlack
   .Replacement.ParagraphFormat.Shading.ForegroundPatternColor =
wdColorBlack
   .Replacement.ParagraphFormat.Shading.BackgroundPatternColor =
wdColorWhite
   .Replacement.ParagraphFormat.Shading.Texture = wdTexture15Percent
   .Execute Replace:=wdReplaceAll
End With

This doesn't work. It applies the outside line to the paragraphs, but
not the foreground & background colors, nor the texture.

But I can apply these on a named paragraph without problems e.g.:

ActiveDocument.Sections(2).Range.Paragraphs(1).Shading.ForegroundPatternColor
= wdColorBlack
ActiveDocument.Sections(2).Range.Paragraphs(1).Shading.BackgroundPatternColor
= wdColorWhite
ActiveDocument.Sections(2).Range.Paragraphs(1).Shading.Texture =
wdTexture15Percent

This works... why does the previous example not?

Plattform: Windows XP Pro
Word 2000 - Spanish (Spain)

Thanks in advance for your help!

Miguel
Helmut Weber - 28 Feb 2006 20:25 GMT
Hi Michael,

i assume, a chr(13), as part of the end-of-cell mark,
isn't a real paragraph, so ParagraphFormat might fail.

Applying the style to the found range,
seems to work here and now, for the whole cell.

Like:

Sub Macro20()
Dim rdcm As Range
Set rdcm = ActiveDocument.Range
With rdcm.Find
  .Text = ""
  .Font.Size = 15
  If .Execute Then
     rdcm.Shading.Texture = wdTexture25Percent
  End If
End With
End Sub

or

With rdcm.Find
  .Text = "tralala"
  If .Execute Then
     rdcm.Shading.Texture = wdTexture15Percent
  End If
End With

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Michael Marti Menzel - 10 Mar 2006 11:21 GMT
Hello Helmut,

thanks so much for your explanation. Actually I'm not dealing with
tables, just with text (some sections do have 2 colums).

I'm still unable to replace paragraph formattings in some cases, but I'm
still investigating the reason (programatic or maybe a VBA shortage ?).

Best,

Michael
 
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.