Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-16-2021, 10:18 AM
Noob_VBA Noob_VBA is offline Copy Between Two Headings/Texts Windows 10 Copy Between Two Headings/Texts Office 2016
Novice
Copy Between Two Headings/Texts
 
Join Date: Nov 2021
Posts: 9
Noob_VBA is on a distinguished road
Default Copy Between Two Headings/Texts

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
Reply With Quote
 



Similar Threads
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
Copy Between Two Headings/Texts Applied Styles to Headings in Multi-Level List; now ALL second level headings are 1.XX 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:49 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft