Awwe Posted November 13, 2016 Share Posted November 13, 2016 (edited) 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: ____________________________________________________________________________________________________________________________________ This is what I want : Edited November 13, 2016 by Awwe Link to comment Share on other sites More sharing options...
water Posted November 13, 2016 Share Posted November 13, 2016 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Awwe Posted November 13, 2016 Author Share Posted November 13, 2016 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. Link to comment Share on other sites More sharing options...
water Posted November 13, 2016 Share Posted November 13, 2016 (edited) 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.aspxI still need to check how to retrieve ListGalleries/Templates (xx above) Edited November 13, 2016 by water Awwe 1 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Awwe Posted November 13, 2016 Author Share Posted November 13, 2016 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.aspxI 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. Link to comment Share on other sites More sharing options...
water Posted November 13, 2016 Share Posted November 13, 2016 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now