Digisoul Posted May 2, 2015 Posted May 2, 2015 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) EndFuncThanks. 73 108 111 118 101 65 117 116 111 105 116
water Posted May 2, 2015 Posted May 2, 2015 (edited) 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 May 2, 2015 by water Gianni and Digisoul 2 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
Digisoul Posted May 2, 2015 Author Posted May 2, 2015 oh, understood. Thank you very much water. 73 108 111 118 101 65 117 116 111 105 116
water Posted May 2, 2015 Posted May 2, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now