Quote:
Originally Posted by macropod
Hi tinfanide,
Try this version:
Code:
Sub Test()
Dim Rng As Range, Str1 As String, Str2 As String
With ThisDocument
With .Content
With .Find
.ClearFormatting
.MatchWildcards = True
.Text = "The Principal"
.Execute
End With
If .Find.Found Then
Set Rng = .Duplicate.Paragraphs.Last.Next.Range
With Rng
While Not .Characters.Last Like "[a-z]"
.End = .End - 1
Wend
Str1 = Trim(.Text)
End With
End If
End With
With .Content
With .Find
.ClearFormatting
.MatchWildcards = True
.Text = "RE: [!13]@^13"
.Execute
End With
If .Find.Found Then
Set Rng = .Duplicate
With Rng
While Not .Characters.Last Like "[a-z]"
.End = .End - 1
Wend
.Start = .Start + 4
Str2 = Trim(.Text)
End With
End If
End With
MsgBox .Path & "\" & Str1 & " " & Str2
'.SaveAs2 FileName:=ThisDocument.Path & "\" & Str1 & " " & Str2, FileFormat:=wdFormatDocumentDefault
End With
End Sub
if you get a message box with the correct contents, you can delete that line and uncomment the next line.
|
Yes. Thanks for the codes.
With a quite careful look at them, I notice ya've used two
Code:
With .Content
End With
to resolve the problem raised by me last post.
Meanwhile, I'm using
Code:
.Find.Wrap = wdFindContinue
to resolve the problem where the find result keeps the first one, not continues with the subsequent one.
Code:
Sub Macro1()
Dim Str1 As String, Str2 As String
Dim Rng As Range
With ThisDocument
With .Content
With .Find
.ClearFormatting
.MatchWildcards = True
.Execute FindText:="The Principal"
End With
If .Find.Found Then
Set Rng = .Duplicate.Paragraphs.Last.Next.Range
With Rng
While Not .Characters.Last Like "[a-z]"
.End = .End - 1
Wend
Str2 = .Text
End With
End If
With .Find
.ClearFormatting
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute FindText:="RE: [!13]@^13"
End With
If .Find.Found Then
Set Rng = .Duplicate
With Rng
While Not .Characters.Last Like "[a-z]"
.End = .End - 1
Wend
.Start = .Start + Len("RE: ")
Str1 = .Text
End With
End If
End With
End With
Debug.Print Str1 & " " & Str2
End Sub