View Single Post
 
Old 11-20-2014, 06:31 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I am not sure what the relevance of the attached document is as it is already named with the number, but the following will do the job:

Code:
Sub SavePolicyDoc()
Dim orng As Range
Dim vNumber As Variant
Dim strText As String
Dim bFound As Boolean
Const strPath As String = "" 'Put the folder path here e.g. "C:\Path\"
    Set orng = ActiveDocument.Range
    With orng.Find
        Do While .Execute(FindText:="Policy number -  [0-9]{1,}", MatchWildcards:=True)
            strText = orng.Text
            bFound = True
            vNumber = Split(strText, "-")
            ActiveDocument.SaveAs Filename:=strPath & Trim(vNumber(UBound(vNumber))) & ".docx"
            Exit Do
        Loop
        If Not bFound Then MsgBox "The policy number was not found"
    End With
    Set orng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote