I have a Word File containing flagged blocks of text viz:
Text 1
Text 1 Line 1
Text 1 Line 2
Text 1 End
Text 2
Text 2 Line 1
Text 2 Line 2
Text 2 Line 3
.
.
Text 2 Line N
Text 2 End
etc.
I need my Excel Macro to find blocks of text between the specified flags "Text X" and "Test X End" then take a copy of the text (not including the flags) and paste it into a second Word Document at a specified location.
I've tried tweaking many of the solutions posted on stack exchange but have been unable to get these to compile and/or run as most seem to assume that I am writing my macro from within Word rather than Excel.
My reason for working within Excel is that I am adding functionality to an existing suite of Excel macros accessed via an Excel Interface.
Current State of the code is:
Sub Word_In_Word_Out()
Application.ScreenUpdating = False
Path = ThisWorkbook.Path
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set inDoc = wrdApp.Documents.Open(Path & "\" & "Word Input" & ".docx")
inDoc.Activate
Dim rng1 As Range
Dim rng2 As Range
Dim strTheText As String
Set rng1 = ActiveDocument.Range
If rng1.Find.Execute(FindText:="Text 2") Then
Set rng2 = ActiveDocument.Range(rng1.End, ActiveDocument.Range.End)
If rng2.Find.Execute(FindText:="Text 2 End") Then
strTheText = ActiveDocument.Range(rng1.End, rng2.Start).Text
MsgBox strTheText
End If
End If
End Sub
This currently stops compilation at the line:
{If rng1.Find.Execute(FindText:="Text 2") Then}
with ".Find" highlighted and an "Argument not Optional" error message