Jump to content

Recommended Posts

Posted

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
Posted

How about this VB code?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Styles is a collection, not an array.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (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 by Servant
Posted

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.

My UDFs and Tutorials:

  Reveal hidden contents

 

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
×
×
  • Create New...