Hi Ilya,
have a look at this one:
Sub Test444()
Dim rTmp As Range
Dim rDcm As Range
Dim iPrg As Integer
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Style = "PStyle B"
While .Execute And rDcm.Text = vbCr
Set rTmp = rDcm
rTmp.start = 0
iPrg = rTmp.Paragraphs.Count
If ActiveDocument.Paragraphs(iPrg - 1).Style = "PStyle A" Then
If ActiveDocument.Paragraphs(iPrg + 1).Style = "PStyle C" Then
ActiveDocument.Paragraphs(iPrg).Range.Delete
rDcm.Collapse Direction:=wdCollapseEnd
End If
End If
Wend
End With
End Sub
You might find resetting search options beforehand useful.
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
>Could anyone please give me a pointer on this?
As usual, I am only trying to show the way,
improvements and stripping off possibly useless code lines
is up to you and the co-readers.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
ilyaa1 - 12 Dec 2004 17:09 GMT
Helmut,
Thanks a lot for the answer. Two issues:
1. .Style can only access the standard styles in word. My document
contains copy-and-pasting from the web, so it has a tyle called
"XStyle", for example. That style shows up in the Styles & Formatting,
but not in .Styles list. How can I access it?
2. I got around the previous problem by selecting all instances of
"XStyle" and converting to a style that is listed in .Styles. When I
ran the script, Word lost responsiveness, was consuming 98% of the CPU,
and stayed that way for about 10 minutes, at which point in time I
killed it. Now, I do have a fairly large document, but scripts that
would remove all hyperlinks in the same size dicument work fine...
I've tried to google for vba-based style modification, but with not
much success. Could you please help me with these issues?
Thanks a lot.
Ilya Ayzenshtok.
Helmut Weber - 12 Dec 2004 22:56 GMT
Hi Ilya,
I am very sorry, I can't reproduce this problem.
If I copy some text (plus pictures) from a web site, the styles,
that come with it, _are_ listed in the styles list in the dialog
"edit find", here and now.
I think I've seen a site on tips on how to clean text that was
copied from the internet, but can't find it again.
Maybe somebody else will know.
Just, at a very long shot, i am doing something like this,
when converting internet content to word-docs:
With .Find
.Text = "^011{1,}"
.Replacement.Text = "^p"
'...
End With
and apply my standard style afterwards.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/