Jump to content

WORD (sentence words counter and selection)


terro
 Share

Recommended Posts

Hi,

I discoverd autoit,;) I'm not a programmer and I get stuck understanding the way word.au manage the sentences in Word 2010.

1) I need to start setting the cursor at the beginning of the Word document.

Then use a kind of loop on the entire document

select the first sentence with 6 words display a message "OK" (the only way I found is unelegant key sequence F8+ F8+F8.:sweating:)

then get and select the next sentence with six words and display "OK".

2) how to remove the "double or triple carriage return" in the same document

Here my piece of code

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oRange, $oWord = _Word_Create(),$oRangeFound, $oRangeText
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.docx", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", _
        "Error opening '.\Extras\Test.docx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

For $I = 1 To 235 Step 1 ; sentence counter
 $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, $I, Default,0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", _
        "Error setting/expanding range." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oRange.Select

Send("{F8}")                ;X3 (F8) allows to select a sentence
Send("{F8}")
Send("{F8}")
sleep(400)                    ; MsgBox(0, "", "OK")
Send("{ESCAPE}")     ; free the sentence selection
Send("^{DOWN}")       ; get to the next sentence

Next

Thank you for your help.

 

Link to comment
Share on other sites

Scene 1 in the example script in the help file for function _Word_DocRangeSet should show you how to get statistics.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You could process all tables and count words/sentences. Then process the whol document and count word/sentences. Subtract the results from the tables part for the final result.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

×
×
  • Create New...