Jump to content

Page Number of found Text


Recommended Posts

Hi there,

I am using  _Word_DocFind to find some text in the .docx file, the search result is okay, but how can I get the page number of the found text ?

Here is my rough attempt:

$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord,"C:\test.docx",False,Default,True)

$oRange = _Word_DocFind($oDoc,"SLR 1985 PRO 3",0,Default,True)
If Not @error Then
    ConsoleWrite("> TXT Found"&@LF)
    $oRange2 = _Word_DocRangeSet($oDoc, $oRange)
    $oRange2.Select
;~  _GetActivePage($oRange2) ; failed
;~  _GetActivePage($oRange) ; failed
;~  ConsoleWrite($oWord.Selection.Information($wdActiveEndAdjustedPageNumber)&@LF); failed
Else
    ConsoleWrite("!Not Found. Error:"&@error&@LF)
EndIf

Func _GetActivePage(ByRef $oWordApp)
    Local $iPage = $oWordApp.Selection.Information($wdActiveEndPageNumber)
    ConsoleWrite(">Active Page:"&$iPage&@LF)
 EndFunc

Thanks.

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

This works for me:

#include <Word.au3>
Global Const $wdActiveEndPageNumber = 3
$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, "C:\temp\test.docx", False, Default, True)

$oRange = _Word_DocFind($oDoc, "SLR 1985 PRO 3", 0, Default, True)
If @error Then
    MsgBox(0, "", "Nothing found!")
Else
    MsgBox(0, "", "Text found on page " & $oRange.Information($wdActiveEndPageNumber))
EndIf
_Word_DocClose($oDoc)
_Word_Quit($oWord)

You do not need to work with a selection (means selecting the text in the GUI). Simply use the Range object (kind of an invisible selection) returned by _Word_DocFind.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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...