Jump to content
Awwe

Word UDF and Numbered lists

Recommended Posts

Awwe

Hi there!

I'm making a script for automating the creation of a word document.
 

#include <Word.au3>


Local $oWord = _Word_Create()
$currentQuestion = 0
$oDoc = _Word_DocAdd($oWord)


$oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 1, Default, 2)

$oRange.Font.Name = "Calibri"
$oRange.Font.Size = 14

$oRange.InsertAfter("Document Title" & @CR & @CR & @CR)
$oRange.Font.Bold = True
$listRange = _Word_DocRangeSet($oDoc, -2)

For $i = 1 To 3
    $oRange = _Word_DocRangeSet($oDoc, -2)
    $oRange.InsertAfter("Category " & $i & @CR)
    $oRange.Font.Bold = True

    $listRange &= _Word_DocRangeSet($oDoc, -2)
    $oRange = _Word_DocRangeSet($oDoc, -2)
    For $n = 1 To 3
        $oRange.InsertAfter("___________________________________" & @CR)
    Next
    $oRange.ListFormat.ApplyNumberDefault

    $oRange.InsertAfter(@CR)
    $oRange.Font.Bold = False

Next

 

This is just a test, later the script will fetch the categories and lines from different text files but that's irrelevant.

I've managed to paste this together by looking at the MSDN site for Word VBA, but I must confess that I'm kind of lost when it comes to working with objects using AutoIt.
I want the numbered lists to keep counting from the previous list, right now they start over from 1 in every category.

 

This is what I get when I run my script:        BDZ9ZF7.png

____________________________________________________________________________________________________________________________________

This is what I want :                                o8taDgK.png

Edited by Awwe

Share this post


Link to post
Share on other sites
water

You could run the macro recorder in Word, create/modify the document to your liking and then translate the resulting VBA macro to AutoIt.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Awwe
8 hours ago, water said:

You could run the macro recorder in Word, create/modify the document to your liking and then translate the resulting VBA macro to AutoIt.

Thanks for the suggestion, I tried it and got this:

Quote

Sub Macro1()

  ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1).StartAt = 666
  
    Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _
        True, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
        wdWord10ListBehavior
End Sub
 

There were additional formating options but I removed them and the macro still works fine.
I'm stuck at how to translate this to Autoit however. If I'm reading it correctly, the Macro creates (or modifies an existing, not sure) List template and then applies it to the list.

 

Share this post


Link to post
Share on other sites
water

Should be something like:

Global $wdNumberGallery = 2
$oRange.ListFormat.ApplyListTemplateWithLevel($oWord.ListGalleries($wdNumberGallery).ListTemplates(1), True)

Listformat is described here: https://msdn.microsoft.com/en-us/library/ff195913.aspx
I still need to check how to retrieve ListGalleries/Templates (xx above)

Edited by water
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Awwe
18 minutes ago, water said:

Should be something like:

Global $wdNumberGallery = 2
$oRange.ListFormat.ApplyListTemplateWithLevel($oWord.ListGalleries($wdNumberGallery).ListTemplates(1), True)

Listformat is described here: https://msdn.microsoft.com/en-us/library/ff195913.aspx
I still need to check how to retrieve ListGalleries/Templates (xx above)

Wow, I actually tried something almost exactly like that but I guess I managed to mess it up since the code you posted worked perfectly!
Thank you so much.

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

×