Jump to content

Delete word highlight and header


Recommended Posts

Good day,

I'm newbie using autoit and trying word manipulation. What I want is to open a word file, remove highlights and header:

Below is my start code:

 

 
#include <Word.au3>
#include <MsgBoxConstants.au3>
 
;~ ; Create application object
Global $oWord = _Word_Create()
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
"Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open test document read-only
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "test.doc", Default, Default, True)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
"Error opening 'test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
 
 
Hope you may help me how to proceed.
Thanks in advance!
 
Regards,
Jun
Link to comment
Share on other sites

  • Moderators

Hi, amalakijr. I have never used the Word UDF, but am sure someone will wander by to show you how to do what you're asking. In the meantime, here is a script to do it without the UDF:

Remove any highlighting:

$oWord = ObjCreate("Word.Application")
$oWord.Visible = True

$oDoc = $oWord.Documents.Open("C:\Users\JeremiaL\Desktop\Test.doc")
$oRange = $oDoc.Range
$oRange.Find.Highlight = True
$oRange.Find.Forward = True

While $oRange.Find.Execute
    If $oRange.HighlightColorIndex <>  0 Then $oRange.HighlightColorIndex = 0
    $position = $oRange.End
    $oRange.Start = $position
WEnd

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...