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