Sign in to follow this  
Followers 0
Servant

How to get the style of a set range on a MS Word document?

4 posts in this topic




$sStyle = $oRange.Style

should do what you want.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Sorry, I forgot to mentioned that these code lines:

$sStyle = $oRange.Find.Style
$sStyle = $oRange.Style

Just returned nothing..

>Exit code: 0
Edited by Servant

Share this post


Link to post
Share on other sites

In this case the Style property returns an object. Try this to get the style of the text you selected:

#include <Word.au3>
Local $oWord = _Word_Create()
If @error <> 0 Then Exit MsgBox(16, "Word UDF: _Word_DocOpen Example", "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $sDocument = "Test_Format.doc"
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)
If @error <> 0 Then Exit MsgBox(16, "Word UDF: _Word_DocOpen Example 1", "Error opening 'Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox(64, "Word UDF: _Word_DocOpen Example 1", "Select range!")
Local $oRange = _Word_DocRangeSet($oDoc, 0)
ConsoleWrite("Selected Text: " & $oRange.Text & @LF)
ConsoleWrite("Style of Selected Text: " & $oRange.Style.NameLocal & @LF)
2 people like this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
    • Jury
      By Jury
      I've failed to find an example of _Word_DocFindReplace which searches for formatted text (I'm looking for stand alone paragraph marks that are formatted other than normal i.e. Bold Italic, Underlined). 
      The reason being that when converting a Word document to html one of the main problems in the results is that a stand alone paragraph mark is converted to an html space that retains the formatting ...>&nbsp;<... thus showing up as a underline _  in a browser when it should be blank.  I've played around with the script and got it to at least un-bold  the first paragraph mark regardless if it was bold or not but I'd like to clear all formatting from any stand alone paragraph marks in the whole document.  Below is what I've done so far (not much more than in the help file I'm afraid) .  Way down at the bottom of the _Word_DocFindReplace  help  text is this parameter but without any examples to be found :
      $bFormat   [optional] True to have the find operation locate formatting in addition to or instead of the find text (default = False) #include <MsgBoxConstants.au3> #include <Word.au3> $processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\' Global $oWord = _Word_Create() Global $sTestfile = $processing & "Testing.docx" ConsoleWrite($sTestfile & @CRLF) Global $oDoc = _Word_DocOpen($oWord, $sTestfile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening file = '" & $sTestfile & "'" & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound = _Word_DocFind($oDoc, "^p", Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = False If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")  
    • ahha
      By ahha
      Okay this is likely due to my not properly understanding objects.
      I'm using _Word_DocRangeSet to extend a range (in this case to the end of a line).
      The issue I've encountered is that extending one range seems to affect another range.
      It may be that an object can't be assigned or equated.
      In any event the program and test file (place in the same directory) illustrate the issue.
      Test 1 - shows the documentation for _Word_DocRangeSet correctly shows how the range is extended and the assigned result is extended.  No problem here just part of my learning.
      Test 2 - like Test 1 but no assignment of the result from  _Word_DocRangeSet is needed.  Again correct and my learning.
      Test 3 - here is where the issue is.  After an assignment to a new object the old one seems to be affected by _Word_DocRangeSet.  This I don't understand (perhaps the assignment is really a namespace pool and points to the same structure like aliases <-- wild guess).
      Test 4 - shows that using .Select can extend the range and leave the original range alone.
      Any hints/pointers on what's going on appreciated.
      Thanks
      WordRangeTesting v1c.au3
      Test for WordRangeTesting v1c.docx
    • ahha
      By ahha
      Okay I've hacked down a large program to illustrate the problem I'm having.
      I'm using the built-in Word UDF (which is great) and am finding a range and then copying it to the clipboard and sticking it in an array for viewing.
      Then extending the range and again copying it to a clipboard and sticking it into the array.
      It seems to drop the ranges randomly.  I can't figure out what I'm doing wrong (or if there's a better way to get a range into a variable).
      Run the program with the test file and you'll see entries being dropped (put test file in same directory as the program).
      Any pointers or help much appreciated.
      Hacked down program for testing Range extend and copy v3c.au3
      Test for Range Copy v1a.docx