![]() |
|
#1
|
||||
|
||||
![]()
Hi tinfanide,
Try something along the lines of: Code:
Dim Rng As Range, Str1 As String, Str2 As String With ThisDocument With .Content With .Find .ClearFormatting .MatchWildcards = True .Text = "The Principal^13[!13]@^13" .Execute End With If .Find.Found Then Set Rng = .Duplicate.Paragraphs.Last With Rng .End = .End - 1 Str1 = Trim(.Text) End With End If With .Find .Text = "RE: [!13]@^13" .Execute End With If .Find.Found Then Set Rng = .Duplicate.Paragraphs.Last With Rng .End = .End - 1 .Start = .Start + 4 Str2 = Trim(.Text) End With End With .SaveAs2 FileName:=.Path & "\" & Str1 & " " & Str2, FileFormat:=wdFormatDocumentDefault End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
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 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? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word Visual Basic error - run time error 504 | crazymorton | Word | 11 | 01-13-2012 04:32 AM |
![]() |
bennypryde | Office | 1 | 01-05-2012 03:33 PM |
Ms Word Error | manesh | Word | 1 | 05-28-2010 07:26 AM |
Runtime error 5487 - Word cannot complete the save to to file permission error | franferns | Word | 0 | 11-25-2009 05:35 AM |
Receive error cannot open this form because an error occurred in BCM 2007 | bornhusker | Outlook | 0 | 06-01-2009 10:28 AM |