Jump to content

numbered paragraphs in Word


Recommended Posts

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

Edited by Jury
Link to comment
Share on other sites

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:

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

 

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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

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:

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

 

Link to comment
Share on other sites

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:

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

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

 

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