![]() |
|
#1
|
||||
|
||||
![]()
Try running the following macro from an empty Word document. Simply edit the entries on the ArrStart & ArrEnd lines to refer to your actual start & end keywords. You can add/delete start & end keywords as necessary. Note that the keyword tests are case-sensitive.
Code:
Sub GetKeyWordStrings() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document Dim ArrStart(), ArrEnd(), i As Long, StrOut As String ArrStart = Array("StartString1", "StartString2", "StartString3") ArrEnd = Array("EndString1", "EndString2", "EndString3") strDocNm = ActiveDocument.FullName strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.doc", vbNormal) While strFile <> "" If strFolder & "\" & strFile <> strDocNm Then StrOut = StrOut & vbCr & strFile & vbCr Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc For i = 0 To UBound(ArrStart) With .Range With .Find .ClearFormatting .Format = False .Forward = True .Wrap = wdFindStop .MatchWildcards = True .Text = ArrStart(i) & "*" & ArrEnd(i) .Execute End With Do While .Find.Found StrOut = StrOut & .Text & vbCr .Collapse wdCollapseEnd .Find.Execute Loop End With Next .Close SaveChanges:=False End With End If strFile = Dir() Wend With ActiveDocument.Range .Text = StrOut .Characters.First.Delete End With Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
maxbeedie | Word | 1 | 11-15-2016 04:04 AM |
![]() |
Greengecko | Word VBA | 5 | 06-14-2016 07:54 AM |
![]() |
AustinBrister | Word VBA | 3 | 06-01-2015 07:00 AM |
Office 2010 Can't Open Or Save Documents in My Documents Folder | trippb | Office | 1 | 07-12-2013 07:29 AM |
Print attachment when it arrive in specific folder with specific subject | visha_1984 | Outlook | 1 | 01-30-2013 10:42 AM |