View Single Post
 
Old 04-16-2012, 07:36 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Paul, thanks for your codes.
I've amended them a bit according to the errors reported.

Code:
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.Range
          With Rng
            .End = .End - 2
            Str1 = Trim(.Text)
          End With
        End If
        With .Find
          .Text = "R"
          .Execute
        End With
        If .Find.Found Then
          Set Rng = .Duplicate.Paragraphs.Last.Range
          With Rng
            .End = .End - 1
            .Start = .Start + 4
            Str2 = Trim(.Text)
          End With
        End If
    End With
    .SaveAs2 FileName:=.Path & "\" & Str1 & " " & Str2, FileFormat:=wdFormatDocumentDefault
End With
But stange things happen then.
Either string can be found, not both.
When I move Str2 in front of Str1,
Str1 cannot be found and
vice versa.

Could ya tell me why?
Reply With Quote