View Single Post
 
Old 01-31-2019, 05:37 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 01/31/2019
Dim oRng As Range
Dim arrFind() As String
Dim lngIndex As Long
Dim strContent
Dim oThisDoc As Document
Dim oDoc As Document
  
  Set oThisDoc = ActiveDocument
  arrFind = Split("1945,1946,1947", ",")
  For lngIndex = 0 To UBound(arrFind)
    oThisDoc.Activate
    strContent = vbNullString
    Set oRng = ActiveDocument.Range
    With oRng.Find
      .ClearFormatting
      .Text = arrFind(lngIndex)
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      Do While .Execute
        strContent = strContent & oRng.Paragraphs(1).Range.Text & vbCr
      Loop
      If strContent <> vbNullString Then
        Set oDoc = Documents.Add(, , wdNewBlankDocument)
        oDoc.Range.Text = strContent
      End If
    End With
  Next lngIndex
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote