![]() |
#1
|
|||
|
|||
![]()
Hello All,
I find this VBA program and have been trying to modify it. I'm having some issues. I'm trying to search multiple word files between two headings. But the headings in each of these word files are not Heading Style format, instead, it is Normal Style. I need the program to search each word documents and output the text/body include tables, photos, etc between the two headings. Any thoughts on how I can do this? Sub CP_Between_Text() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, strTmp As String, strOut As String Dim wdDoc As Document, Rng As Range, i As Long Dim FindWord1, FindWord2 As String Dim result As String FindWord1 = "System Safety Assessment Summary" FindWord2 = "Hardware Considerations" strDocNm = ActiveDocument.FullName strFolder = GetFolder: If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.docx", vbNormal) While strFile <> "" If strFolder & "" & strFile <> strDocNm Then Set wdDoc = Documents.Open(FileName:=strFolder & "" & strFile, AddToRecentFiles:=False, Visible:=False) strTmp = "" With wdDoc With .Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = FindWord1 .Replacement.Text = "" .Format = False .Forward = True .Wrap = 1 .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute For i = 0 To UBound(Split(.Text, ",")) .Text = Split(.Text, ",")(i) .Execute If .Found = True Then strTmp = strTmp & ", " & Split(.Text, ",")(i) Next End With If strTmp <> "" Then strOut = strOut & vbCr & strFile & ": " & strTmp .Close SaveChanges:=True End With End If strFile = Dir() Wend Set wdDoc = Nothing ActiveDocument.Range.Text = "The following matches were made:" & strOut 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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need to copy texts from excel and paste in to the Notepad++ in between the particular tags | ganesang | Word VBA | 2 | 08-27-2018 02:05 AM |
![]() |
NNL | Word | 1 | 08-09-2017 02:52 PM |
Numbered headings not working as expected after customising headings | seanspotatobusiness | Word | 5 | 03-03-2017 04:44 AM |
Copy, Paste, and Format Multiple Headings | Dretherix | Word VBA | 2 | 02-12-2016 08:26 AM |
Trying to find and copy all headings at the same time | WaltR | Word | 7 | 08-21-2012 03:12 PM |