Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 10-01-2022, 07:40 PM
hcl75 hcl75 is offline How to use Word Macro to change all highlighted words as mark-up? Windows 10 How to use Word Macro to change all highlighted words as mark-up? Office 2019
Novice
How to use Word Macro to change all highlighted words as mark-up?
 
Join Date: Oct 2022
Posts: 1
hcl75 is on a distinguished road
Post How to use Word Macro to change all highlighted words as mark-up?

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  
Old 10-02-2022, 07:14 AM
macropod's Avatar
macropod macropod is offline How to use Word Macro to change all highlighted words as mark-up? Windows 10 How to use Word Macro to change all highlighted words as mark-up? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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  
Old 10-02-2022, 07:28 AM
macropod's Avatar
macropod macropod is offline How to use Word Macro to change all highlighted words as mark-up? Windows 10 How to use Word Macro to change all highlighted words as mark-up? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
means that, if any cell in the range contains 'T', then all Finds will be wildcard based.

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  
Old 10-08-2022, 02:39 PM
macropod's Avatar
macropod macropod is offline How to use Word Macro to change all highlighted words as mark-up? Windows 10 How to use Word Macro to change all highlighted words as mark-up? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Closed Thread

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
How to use Word Macro to change all highlighted words as mark-up? Is this even possible: extrapolating highlighted words angiesnow Word 2 08-12-2018 03:40 AM
How to use Word Macro to change all highlighted words as mark-up? Macro in Word to track colour of highlighted text BABZ Word VBA 1 01-09-2017 10:33 PM
How to use Word Macro to change all highlighted words as mark-up? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft