Nerd901
09-29-2011, 08:13 AM
Hi,
I have a "big" problem.
I'm development a program in ms office word 2010.This program need find a character or tag,apply a style in text between tags / characters, and erase this tags.
aplicar
I managed to find a one tag and erase they, but with two different tags. I really dont know.
I thought about in use a if, and count the two first character,or paragraph start. but I couldn't find a function.
Text Exemple:
H1TESTH1
H2THIS IS MY TESTH2
H1TESTINGH1
H2THIS WILL BE MY TESTH2
My code:
Sub Titulo()
Dim StartWord As String, EndWord As String
StartWord = "H1"
EndWord = "H1"
Do While ActiveDocument.Content.Duplicate.Find.Execute(findtext:=StartWord) = True
With ActiveDocument.Content.Duplicate
.Find.Execute findtext:=StartWord & "*" & EndWord, MatchWildcards:=True
.MoveStart wdCharacter, Len(StartWord)
.MoveEnd wdCharacter, -Len(EndWord)
.ParagraphFormat.Style = ("Title")
End With
With Selection.Find
.ClearFormatting
.Text = "H1"
With .Replacement
.Text = ""
.ClearFormatting
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceOne
End With
Loop
End Sub
Very tks.
I have a "big" problem.
I'm development a program in ms office word 2010.This program need find a character or tag,apply a style in text between tags / characters, and erase this tags.
aplicar
I managed to find a one tag and erase they, but with two different tags. I really dont know.
I thought about in use a if, and count the two first character,or paragraph start. but I couldn't find a function.
Text Exemple:
H1TESTH1
H2THIS IS MY TESTH2
H1TESTINGH1
H2THIS WILL BE MY TESTH2
My code:
Sub Titulo()
Dim StartWord As String, EndWord As String
StartWord = "H1"
EndWord = "H1"
Do While ActiveDocument.Content.Duplicate.Find.Execute(findtext:=StartWord) = True
With ActiveDocument.Content.Duplicate
.Find.Execute findtext:=StartWord & "*" & EndWord, MatchWildcards:=True
.MoveStart wdCharacter, Len(StartWord)
.MoveEnd wdCharacter, -Len(EndWord)
.ParagraphFormat.Style = ("Title")
End With
With Selection.Find
.ClearFormatting
.Text = "H1"
With .Replacement
.Text = ""
.ClearFormatting
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceOne
End With
Loop
End Sub
Very tks.