Jump to content

Recommended Posts

Posted (edited)

As near as I can ascertain using the Word UDF the paragraph count does not count the numbered paragraphs in a document but counts something like all paragraphs (numbered , un-numbered, indented) minus empty lines.  Is there any easy way of getting the first level numbered paragraph numbers?  You'll see in my test document there are just 7 numbered paragraphs.

#include <Word.au3>
#include <Array.au3>


Local $oWord = _Word_Create()
Local $sDocument =  @MyDocumentsDir & "\test.docx"
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)

$oRange = $oDoc.Range
$sText = $oRange.Text
$aLines = StringSplit($sText, @CR)
_ArrayDisplay($aLines)

$wdPropertyParas = 24
$sParas = $oDoc.BuiltInDocumentProperties($wdPropertyParas).Value
$sParas = $sParas
ConsoleWrite($sParas & @CRLF)

 

test.docxFetching info...

Edited by Jury
Posted

Can't test at the moment but I suggest something like this:

$iCount = $oDoc.Content.ListFormat.CountNumberedItems(1)
MsgBox(0, "Level 1", "Number of level 1 items: " & $iCount)

as described here in example 2: https://msdn.microsoft.com/en-us/library/ff820795(v=office.14).aspx

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

That's because AutoIt does no support named parameters. Just use the number by itself.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Thanks again Water (an others) I've tried so many things:

$oDoc.Content..Lists(1).ListParagraphs

$oDoc.Content.ListFormat.CountNumberedItems(1)

and many others

always getting the number of lines with content (17) or the total number of lines (34) but never the number of level 1 paragraphs. 

I'm now looking at the possibility of paragraph numbers being a field - I see  msdn.microsoft.com mention LISTNUM field - what do you think?

If no luck there I'll move on and write the contents into an array (no doesn't preserve para numbers) convert to html (this does preserve the paragraph numbers) and search for the words/phrases I want and list the paragraph number and position in the paragraph (paragraph & start character)  THEN go back to the word doc and see about highlighting all the instances of the words/phrases found - which is what I want to end up with i.e. an open word doc with all the searched for words/phrases highlighted (if possible to highlight multiple instances on a document).

I've looked at an very old commercial vba script and see that they did something with pick 0 left margin paragraphs and then go down the doc looking for the next sequential number  0 left margin paragraph - but this assumes all 0 left margin paragraphs are numbered paragraphs.

 

Again thanks for your time as always,

jury

Edited by Jury
Posted

I have no access to a Windows system at the moment. Will check as soon as I return to my office.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

This example counts the number of Level 1 list paragraphs:

#include <Word.au3>

Local $oWord = _Word_Create()
Local $sDocument = "C:\temp\test.docx"
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)

Global $iLists = $oDoc.ListParagraphs.Count
Global $iLevel = 0

For $i = 1 To $iLists
    If $oDoc.ListParagraphs($i).Range.ListFormat.ListLevelNumber = 1 Then $iLevel = $iLevel + 1
Next
MsgBox(0, "", "Number of level 1 paragraphs: " & $iLevel)

_Word_Quit($oWord)

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Water you are a star (as always).  I will study this.  There are about four things I'd never have done in a million iterations - it seems like I tried nearly that many variations!

Thanks again,

Joe

Posted

I just used Google and found something similar on Stackoverflow: https://stackoverflow.com/questions/8424573/word-2010-vba-manipulating-numbered-lists
It seems to be a brute force method counting all list paragraphs with the needed list level - but it seems to work ;)

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...