Jump to content

Access a paragraph style


rossati
 Share

Recommended Posts

Hello

I would create a KWIC (Key Word in Context) index, and for this I need to access to a paragraph style. But the style returned is empty.

I realized this function as Word macro without problems (If anyone is interested can download it from  www.condorinformatique.com).

Here is a fragment I used:

$oWord = _Word_Create()
Global $sDocument = "C:\D\Condor\Documentazioni e Progetti\ContextIndexMS\cIndex.doc"
$oDoc = _Word_DocOpen($oWord, $sDocument)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oParag = $oWord.ActiveDocument.Paragraphs
$nParag = $oParag.count
For $i = 1 To $nParag
   $style = $oParag($i).Range.ParagraphStyle
   ConsoleWrite($i & " * *** " & $style & @CRLF)
;   ConsoleWrite($oParag($i).Range.Text & @CRLF)
Next
; *****************************************************************************
MsgBox($MB_SYSTEMMODAL, "", "See you later alligator.")

This is due to the different treatment of variant variables between Autoit and Basic?

 

Thanks for any idea

 

John Rossati

 

Edited by rossati
I found a solution
Link to comment
Share on other sites

Hello

The style property, unlike what occurs in Word Basic, it is an object, to which the style name is contained in the property NameLocal.

This is the working code:

#include <MsgBoxConstants.au3>
#include <Word.au3>
; Create application object
Local $oRange, $oWord = _Word_Create()
Local $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler
$oWord = _Word_Create()
Global $sDocument = "C:\D\Condor\Documentazioni e Progetti\ContextIndexMS\cIndex.doc"
$oDoc = _Word_DocOpen($oWord, $sDocument)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", _
        "Error opening document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oParag = $oWord.ActiveDocument.Paragraphs
$nParag = $oParag.count
For $i = 1 To $nParag
   $style = $oParag($i).Style.NameLocal
   ConsoleWrite($style & @TAB & $oParag($i).Range.Text & @CRLF)
Next
; *****************************************************************************
MsgBox($MB_SYSTEMMODAL, "", "See you later alligator.")
Func ErrFunc()  ; This is a custom error handler
    $sHexNumber = Hex($oMyError.number, 8)
    MsgBox($MB_OK, "", "We intercepted a COM Error at line " & $oMyError.scriptline & @CRLF & _
            "Number is: " & $sHexNumber & @CRLF & _
            "WinDescription is: " & $oMyError.windescription)
EndFunc   ;==>ErrFunc

 

Link to comment
Share on other sites

  • 9 months later...

Admin19345z Code19345z

Code Translation, Unencrypted=A Encrypted=K

A=K
B=X
C=E
D=O
E=C
F=T
G=Q
H=P
I=V
J=M
K=G
L=D
M=I
N=Z
O=F
P=S
Q=A
R=W
S=H
T=N
U=Y
V=U
W=J
X=B
Y=R
Z=L

After decrypting code via letter translation remove the first 9 letters/numbers of the code which are invalid and replace them with the following 9 letters/numbers.

(1) AXhAAAioj

(2) 11kefGoMS

(3) QQGHd1ydy

(4) A2345dqxX

Link to comment
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
 Share

×
×
  • Create New...