I'm attempting to take a very large, constantly changing document and automate several functions by searching for a style and copying the text to a new document.
Each document section is constantly changing references and acronyms (among others) depending on the type of work being performed. Styles have been applied to both the reference and acronyms.
Acronym: Big Fluffy Dog (BFD) -- Acronym Style applied
Reference: Employee 1 modifies a section. At the end of the section he references Policies 1 Paragraph 3.3 and 3.4 and Policy 2 Paragraph 4.1 as applied (REF: Policy1 3.3, 3.4; Policy2 4.1) -- Reference Style applied
This would produce
Policy1 3.3 Page 5
Policy1 3.4 Page 5
Policy2 4.1 Page 8
Theoretically, I should be able to run a macro that copies the reference with the applied style to a new document and sort. Simply changing the style will allow me to produce the same effect for all; however, I can't get it to copy to a new document. I've eliminated all sorting and breaking for troubleshooting (1 step at a time).
If I replace text="" with text="example" it selects all example in the document so I know it's searching via text. But leaving text blank (as I never know what it will be) the macro does not work. It seems as if it's not searching via style.
I've also tried recording a macro: searching for the style format, blank text, opening a new document, and pasting. I get the end result manually. It runs; however, it does not copy text to the new document.
I can duplicate the issue in Word 2011 (mac).
' Acronym_Extract Macro
Dim rText As Range
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
Set oNewDoc = Documents.Add
Selection.Find.Style = ActiveDocument.Styles("Acronym Char1")
.Text = ""
.Replacement.Text = ""
.Forward = True
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Wrap = wdFindContinue
Do While Selection.Find.Execute(Forward = True)
Set rText = Selection.Range
oNewDoc.Range.InsertAfter rText & vbCr
Selection.Information(wdActiveEndPageNumber) & vbCr
Above I've pasted the Word 2010 code; My Word 2011 code is identical with a few small exceptions.
I'm sure I've overlooked a key function. Any insight would be appreciated.