arts Posted October 31, 2014 Share Posted October 31, 2014 (edited) Hello, I can search through a Word document using Word.au3 but the search is limited to the main body of the document. Is it possible to search in the other parts like headers, footers, text-boxes, footnotes, image legends/captions or any other area that is outside the main body? I think this is called the StoryRanges of the StoryTypes as decribed in this macro . Can it be done with AutoIt? Thank you. Edited October 31, 2014 by arts Link to comment Share on other sites More sharing options...
water Posted November 1, 2014 Share Posted November 1, 2014 Parameter $vSearchRange allows to specify the search range. What happens when you pass the needed StoryRange? Can't test at the moment as I have no Office installed here. 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 More sharing options...
arts Posted November 1, 2014 Author Share Posted November 1, 2014 Parameter $vSearchRange allows to specify the search range. What happens when you pass the needed StoryRange? Can't test at the moment as I have no Office installed here. I'll try and let you know later, Water. Thank you. Link to comment Share on other sites More sharing options...
arts Posted November 3, 2014 Author Share Posted November 3, 2014 (edited) Well, using this modified piece of code from your "_Word_DocFind Example" I can find the word "Story" in Footnotes. Now I 'only' have to find a way of looping over the other parts of the document too... Local $Footnotes = $oDoc.Footnotes.Count ConsoleWrite("Footnotes: " & $Footnotes & @CRLF ) For $n = 1 to $Footnotes $MyFootnote = $oDoc.Footnotes($n).range $oRangeFound = _Word_DocFind($oDoc, "Story", $MyFootnote, Default, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating the specified text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = True MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Last occurrence of string 'Story' in the document marked as bold.") Next Edited November 3, 2014 by arts Link to comment Share on other sites More sharing options...
water Posted November 3, 2014 Share Posted November 3, 2014 Global Const $wdFootnotesStory = 2 For $oStory In $oDoc.StoryRanges ; Process all Stories of the document If $oStory = $wdFootnotesStory Then ; Only process Footnotes $oStoryRange = $oStory While 1 ; Loop through the footnotes $oStoryRange = $oStoryEange.NextStoryRange If $oStoryRange = 0 Then ExitLoop ; No more footnotes ; Process $oStory.NextStoryRange here WEnd EndIf Next Untested example how to loop through the stories and process all footnotes. 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 More sharing options...
arts Posted November 4, 2014 Author Share Posted November 4, 2014 (edited) Global Const $wdFootnotesStory = 2 For $oStory In $oDoc.StoryRanges ; Process all Stories of the document If $oStory = $wdFootnotesStory Then ; Only process Footnotes $oStoryRange = $oStory While 1 ; Loop through the footnotes $oStoryRange = $oStoryEange.NextStoryRange If $oStoryRange = 0 Then ExitLoop ; No more footnotes ; Process $oStory.NextStoryRange here WEnd EndIf Next Untested example how to loop through the stories and process all footnotes. I couldn't make it work, water. Probably, my fault. Note that my solution above works and gets all Footnotes in the document (tested with a 15 pages doc with many footnotes in each page). But I need more than footnotes. So, now I need to create a global routine that can address headers, footers, text-boxes, footnotes, image legends/caption, comments, etc. in a run. Your approach with '$oDoc.StoryRanges' seems very interesting and I'll try to explore it tomorrow. Thank you! Edited November 4, 2014 by arts Link to comment Share on other sites More sharing options...
water Posted November 4, 2014 Share Posted November 4, 2014 The following script loops through all Stories, processes the footnotes and writes them to the Console. #include <word.au3> $oWord = _Word_Create() $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test.docx") Global Const $wdFootnotesStory = 2 For $oStory In $oDoc.StoryRanges ; Process all Stories of the document If $oStory.StoryType = $wdFootnotesStory Then ; Only process Footnotes $oStoryRange = $oStory While $oStoryRange.NextStoryRange <> 0 ; Loop through the footnotes ; Process $oStory.NextStoryRange here ConsoleWrite("Footnotes: " & @CRLF & $oStoryRange.Text) $oStoryRange = $oStoryRange.NextStoryRange WEnd EndIf Next arts 1 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 More sharing options...
Solution arts Posted November 4, 2014 Author Solution Share Posted November 4, 2014 The following script loops through all Stories, processes the footnotes and writes them to the Console. #include <word.au3> $oWord = _Word_Create() $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test.docx") Global Const $wdFootnotesStory = 2 For $oStory In $oDoc.StoryRanges ; Process all Stories of the document If $oStory.StoryType = $wdFootnotesStory Then ; Only process Footnotes $oStoryRange = $oStory While $oStoryRange.NextStoryRange <> 0 ; Loop through the footnotes ; Process $oStory.NextStoryRange here ConsoleWrite("Footnotes: " & @CRLF & $oStoryRange.Text) $oStoryRange = $oStoryRange.NextStoryRange WEnd EndIf Next Yes, this one gets every footnote. I'll explore this to try to get all I need. Thank you very much, water! Link to comment Share on other sites More sharing options...
water Posted November 5, 2014 Share Posted November 5, 2014 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 More sharing options...
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