Servant Posted April 12, 2014 Posted April 12, 2014 How can I programatically find the styles of all the sentences on a Microsoft Word document? I tried this code but it didn't work: #include <Word.au3> Global $oWord, $oDoc $oWord = _Word_Create() $oDoc = _Word_DocGet($oWord, 1) Local $sCount = $oDoc.Sentences.Count For $i = 0 To $sCount - 1 Local $oRange = _Word_DocRangeSet($oDoc, -1, $wdSentence, $i, $wdSentence, 1) ConsoleWrite("The style of this sentence is: " & $oRange.Style & @LF) Next http://developingsites.blogspot.com
water Posted April 12, 2014 Posted April 12, 2014 How about this VB code? Servant 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
Servant Posted April 12, 2014 Author Posted April 12, 2014 I tried this code in AutoIt with my posted Microsoft Word document: Local $styles = $oDoc.Styles ConsoleWrite(UBound($styles) & @LF) But it just gives me a result of "0".. http://developingsites.blogspot.com
water Posted April 12, 2014 Posted April 12, 2014 Styles is a collection, not an array. 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
Servant Posted April 13, 2014 Author Posted April 13, 2014 (edited) I tried this, I don't know if I write it right: For $styleLoop In $oDoc.Styles If $styleLoop.InUse = True Then ConsoleWrite(".InUse : " & $styleLoop.InUse & @LF) With $oDoc .Content.Find .ClearFormatting .Text = "" .Style = $styleLoop .Execute Format := True If $oDoc = True Then ConsoleWrite("Style Name : " & $styleLoop.Name & @LF) EndIf EndWith EndIf Next And it didn't write the Style Name.. Actually, what I want is to create a script that will manipulate all the paragraphs every after four different specific styles whether they're non-standard or standard.. And I don't think this kind of code will solve my goal... Edited April 13, 2014 by Servant http://developingsites.blogspot.com
water Posted April 13, 2014 Posted April 13, 2014 Replace this code With $oDoc .Content.Find .ClearFormatting .Text = "" .Style = $styleLoop .Execute Format := True witht the _Word_DocFindEX function I posted in the other thread. The result is the range of the header which then can be changed, deleted etc. Servant 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
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