Group: microsoft.public.word.vba.general
From: IdontWantSpam@nospam.net (Edward Thrashcort)
Date: Tuesday, October 23, 2007 3:34 PM
Subject: Re: Macro Find and Replace with styles

> Hi Edward,

"EDDIE" WILL BE FINE THANKS ;-)

Sub ReformatBetweenTags()
Dim a, b As Long
Dim oRange As Range

Selection.HomeKey Unit:=wdStory

With Selection.Find
.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

While .Execute
Selection.Delete
a = Selection.Range.End
.Text = "
"
If .Execute Then
Selection.Delete
b = Selection.Range.Start
Set oRange = ActiveDocument.Range(a, b)
oRange.Style = ActiveDocument.Styles("Heading 1")
End If
.Text = ""
Wend
End With

Set oRange = Nothing
End Sub


Eddie

> *From:* Chris
> *Date:* Wed, 22 Aug 2007 02:14:01 -0700
>
> Hi Edward,
>
> thanks for your fast reply.
>
> Can u give me a code example for this workaround. Im very new in vba
> macros, so it would be very helpful....
>
> Thanks in advance.
>
> Chris
>
> "Edward Thrashcort" wrote:
>
> > I remember having a similar problem which I had to kludge my way around.
> > The trouble is that the (*) part of the search text can be ANYTHING
> > including the whole document!
> >
> >
> > Something like this
> >
> > - find first tag
> > Do while found
> > - delete selection
> > - get the range end position of the cursor "a"
> > - find closing tag
> > - get the range start "b"
> > - delete the selection
> > - select the range between (a+1) abd (b-1)
> > - reformat
> > - find first tag
> > loop
> >
> > Eddie
> >
> >
> > > *From:* Chris
> > > *Date:* Wed, 22 Aug 2007 01:32:02 -0700
> > >
> > > Hi,
> > >
> > > i have a macro which formats the text between Html-Tags like
> > > Text
> > > with standard header styles. The problem is that my whole document
> > > will be replaced with this format style. But i only want to format
> > > the text between the HTML-Tags.
> > > Her is my snippet:
> > >
> > > With ActiveDocument.Range.Find
> > > .ClearFormatting
> > > .Replacement.ClearFormatting
> > > .Format = True
> > > .MatchWildcards = True
> > > .Text = "(\)(*)(\)"
> > > .Replacement.Text = "\2"
> > > .Replacement.Style =
> > > ActiveDocument.Styles(WdBuiltinStyle.wdStyleHeading1)
> > > .Execute Replace:=wdReplaceAll
> > > End With
> > >
> > > Many thanks for any advice...
> > >
> > > Chris
> > >
> >
> >
>

Safety Articles | News in English | 20lbs in 30 days | Bluegrass | Usenet Newsfeeds