In that case, you might try the following two macros.
The first is a variation of the original one but now saves the Excel workbook to the same folder and with the same name as the document. The second one opens that (updated) workbook to import the updates. So, provided the edited workbook's name is kept the same as the document's and is returned to the same folder, the updates should work seamlessly. As you will see, much of the code for the export and import is the same.
Sub ExportHighlightText()
Dim appXL As New Excel.Application, xlWB As Excel.Workbook, xlWS As Excel.Worksheet, i As Long
Set xlWB = appXL.Workbooks.Add: Set xlWS = xlWB.Worksheets(1)
appXL.Visible = True
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.Highlight = True
.Execute
End With
Do While .Find.Found
Select Case .HighlightColorIndex
Case wdYellow
i = i + 1
xlWS.Cells(i, 1).Value = .Text
Case wdBrightGreen
i = i + 1
xlWS.Cells(i, 2).Value = .Text
End Select
If .End = ActiveDocument.Range.End Then Exit Do
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
xlWB.SaveAs FileName:=Split(ActiveDocument.FullName, ".doc")(0) & ".xls", FileFormat:=xlExcel8, AddToMRU:=False
Set xlWS = Nothing: Set xlWB = Nothing: Set appXL = Nothing
End Sub
Sub ImportHighlightText()
Dim appXL As New Excel.Application, xlWB As Excel.Workbook, xlWS As Excel.Worksheet, i As Long
Set xlWB = appXL.Workbooks.Open(FileName:=Split(ActiveDocument.FullName, ".doc")(0) & ".xls", ReadOnly:=True, AddToMRU:=False)
Set xlWS = xlWB.Worksheets(1)
appXL.Visible = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.Highlight = True
.Execute
End With
Do While .Find.Found
Select Case .HighlightColorIndex
Case wdYellow
i = i + 1
.Text = xlWS.Cells(i, 1).Value
Case wdBrightGreen
i = i + 1
.Text = xlWS.Cells(i, 2).Value
End Select
If .End = ActiveDocument.Range.End Then Exit Do
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
xlWB.Close: appXL.Quit
Set xlWS = Nothing: Set xlWB = Nothing: Set appXL = Nothing
End Sub
Bookmarks