![]() |
|
#1
|
|||
|
|||
|
I have used a Word Macro to highlight typos according to a word list (an Excel file). However, I turned on the track changes and the result did not change as a mark-up record because I used that Macro to check whether a document with 200 pages has any typos. I tried to add the open track changes function to the Macro, but it ran very slow, or it deleted the original typo and replaced a typo then highlighted it. Does anyone know how to just write another macro to change those highlighted texts into mark-up records? Then I can just click accept or reject. Thank you for reading this post. Code:
Option Explicit
Sub PR()
Dim Path As String
Dim objExcel As Object
Dim iCount As Integer
Dim VChar(2000) As String
Dim maxCount As Integer
Dim RT As Boolean
Path = "D:\macro\R.xlsx"
RT = ActiveDocument.TrackRevisions
ActiveDocument.TrackRevisions = False
'Highlight variant characters
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open Path
For iCount = 2 To 2000
VChar(iCount) = objExcel.ActiveWorkbook.Sheets(1).Cells(iCount, 1)
If objExcel.ActiveWorkbook.Sheets(1).Cells(iCount, 3) = "T" Then _
Selection.Find.MatchWildcards = True
If Len(VChar(iCount)) = 0 Then Exit For
Next iCount
maxCount = iCount - 1
' maxCount is the total number of entries
objExcel.ActiveWorkbook.Close
objExcel.Quit
Options.DefaultHighlightColorIndex = wdTurquoise
Selection.HomeKey Unit:=wdStory
' It is not necessary to move the cursor as there is only replacement.
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Replacement.Text = "^&"
.Wrap = wdFindStop ' Up to end of document
' Keep settings outside the loop to save steps
For iCount = 2 To maxCount
.Text = VChar(iCount)
.Execute Replace:=wdReplaceAll
Next
End With
ActiveDocument.TrackRevisions = RT
End Sub
Last edited by hcl75; 10-02-2022 at 07:45 AM. |
|
#2
|
||||
|
||||
|
Cross-posted at: excel - How to use Word Macro to change all highlighted words as mark-up? - Stack Overflow
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
||||
|
||||
|
Your code has no hope of working since the Find/Replace block is only run after the workbook has closed.
Furthermore, your use of: Code:
If objExcel.ActiveWorkbook.Sheets(1).Cells(iCount, 3) = "T" Then Selection.Find.MatchWildcards = True Finally, your use of 'Selection' and failure to switch off screen updating is what causes the macro to run slowly. To see how to do this properly, check out: https://www.msofficeforums.com/word-...-not-mail.html, and especially posts 5# and #6 in that thread.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#4
|
||||
|
||||
|
hcl75: Kindly don't go deleting post content after replies have been posted. Doing so destroys the context of the answers and the thread's usefulness for anyone else. Post restored.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| word macro |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PowerPoint macro to change words between quotes to italic needed | KarenK13 | PowerPoint | 9 | 01-12-2020 12:59 PM |
Is this even possible: extrapolating highlighted words
|
angiesnow | Word | 2 | 08-12-2018 03:40 AM |
Macro in Word to track colour of highlighted text
|
BABZ | Word VBA | 1 | 01-09-2017 10:33 PM |
How to mark underlined words in a sentence as A, B, C, D (beneath the words)
|
thudangky | Word | 13 | 12-12-2013 02:22 AM |
| Macro to mark non-coloured/non-highlighted text as hidden | PeterB | Word | 0 | 10-28-2009 07:54 AM |