I have an Excel Worksheet, with a list of different Headings. These Headings are also in a Word Document, but in the Word Document, there is unnecessary information as well. What I am trying to do and sorry for my coding I am just learning is:
- To open the Word Document from Excel
- Scan the Excel Worksheet Column A for all Heading
- Compare the Headings with the Headings in The Word Document
- If they are the same, then copy them in another Word Document (the complete paragraph until the next Heading1)
- If they are not the same, they can be ignored
- This should then be a loop, so it scans it until all Heading from Excel are find and copyied
What I tried so far is this:
Sub Search_Word_Document()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("file:///J:\Test.docx")
With ActiveDocument.Content.Find
FindWord = Columns("A:A").Value
With .Style = ActiveDocument.Styles("Heading 1")
wrdApp.Selection.WholeStory
wrdApp.Selection.Find.ClearFormatting
With wrdApp.Selection.Find
.Text = FindWord
.Forward = True
.Style = ActiveDocument.Styles("Heading1")
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Its opening the document fine, but then the finding for the text out of the columns is absolutely not working as well as finding the Headings. Thank you for your help.