Efo74 3 Posted July 6, 2015 Hello,I would like to know if there is a way to justify text in Word via Autoit.Tahnk you Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
water 2,164 Posted July 6, 2015 Sure. Autoit comes with a Word UDF, Use function _Word_DocRangeSet to select the paragraph to justify.Then use$oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustifyThe WdParagraphAlignment enumeration can be found here: https://msdn.microsoft.com/en-us/library/bb237926(v=office.12).aspx 1 232showtime reacted to this Hide water's signature Hide all signatures My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - WikiOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki Share this post Link to post Share on other sites
Efo74 3 Posted July 6, 2015 Thank you, now I will try:-) Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
Efo74 3 Posted July 6, 2015 Hello,I have made some test, but if I have tree different line of text, I can't make 3 different type of justifications. I don't undestand exactly how _Word_DocRangeSet function works. Can someone make me a shot example ?3 lines like this ...this is the first linethis is the second linethis is the third lineThank you all for your support Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
JLogan3o13 1,519 Posted July 6, 2015 You state you have made some test. Please post what you have, even if it is not working as you would like it to. This will help us help you Hide JLogan3o13's signature Hide all signatures √-1 2^3 ∑ π, and it was delicious! How to get your question answered on this forum! Share this post Link to post Share on other sites
Efo74 3 Posted July 7, 2015 This is an example that does not work. #include <Word.au3>Local $oWord = _Word_Create()$oDoc = _Word_DocAdd($oWord)$oRange = _Word_DocRangeSet($oDoc, -1, Default, 2, Default, 1) ;???!!!!????$oRange.ParagraphFormat.Alignment = 0 ;left$oWord.Selection.TypeText("Test Line1 left justify")$oRange.ParagraphFormat.Alignment = 1 ;center$oWord.Selection.TypeParagraph()$oWord.Selection.TypeText("Test Line2 center justify")$oRange.ParagraphFormat.Alignment = 2 ;right$oWord.Selection.TypeParagraph()$oWord.Selection.TypeText("Test Line3 right justify") Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
goss34 1 Posted July 7, 2015 Does this help? (test.doc has just 3 lines of text)#include <Word.au3> ; Create application object Local $oRange, $oWord = _Word_Create() ; Open the test document Local $oDoc = _Word_DocOpen($oWord, @DesktopDir & "\Test.doc", Default, Default, True) ; Set default alignment 0= Left, 1 = Centre, 2 = Right Local $wdAlignParagraphJustify = 0 ; Move line 1 $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 0, Default, 2) Local $wdAlignParagraphJustify = 2 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify ; Move line 2 $oRange = _Word_DocRangeSet($oDoc, 0, $wdParagraph, 1, Default, 2) Local $wdAlignParagraphJustify = 1 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify Share this post Link to post Share on other sites
Efo74 3 Posted July 7, 2015 Sorry, but it does not work,Word 2013 opens with no blank page ... nothing appear Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
goss34 1 Posted July 7, 2015 Have you created a document called test.doc on your desktop and saved 3 lines of test in it before running the code?I am running version 3.3.12.0 and Word 2010 - I do not have access to 2013 currently but it works ok with my setup and the above code. Share this post Link to post Share on other sites
goss34 1 Posted July 7, 2015 (edited) Tested on 2013 and opened as read only - try this:#include <Word.au3> ; Create application object Local $oRange, $oWord = _Word_Create() ; Open the test document Local $oDoc = _Word_DocOpen($oWord, @DesktopDir & "\Test.docx", Default, Default, False) ; Set default alignment 0= Left, 1 = Centre, 2 = Right Local $wdAlignParagraphJustify = 0 ; Move line 1 $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 0, Default, 2) Local $wdAlignParagraphJustify = 2 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify ; Move line 2 $oRange = _Word_DocRangeSet($oDoc, 0, $wdParagraph, 1, Default, 2) Local $wdAlignParagraphJustify = 1 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustifyText in my docx: (no character returns after each line)This is line 1 of the test document.This is line 2 of the test document.This is line 3 of the test document. Edited July 7, 2015 by goss34 Share this post Link to post Share on other sites
water 2,164 Posted July 7, 2015 Will test as soon as I return to my office. Hide water's signature Hide all signatures My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - WikiOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki Share this post Link to post Share on other sites
Efo74 3 Posted July 7, 2015 Thank you very much for the support goss34,ok, it works, but I thought it was possible to write a line of text, apply formatting and then save the document, and therefore not from a document already written (saved) Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
water 2,164 Posted July 7, 2015 Sure this is possible.Open a new document, use _Word_DocRangeSet to set the range then use $oRange.InsertAfter to insert some text at the end of the document. $oRange is expanded to include the new text. So all formatting applied to $oRange includes the next text. Hide water's signature Hide all signatures My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - WikiOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki Share this post Link to post Share on other sites
Efo74 3 Posted July 8, 2015 Thant you,today I am out of office, but Tomorrow i will try using $oRange.InsertAfterI keep you updated Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
goss34 1 Posted July 8, 2015 So here's an example for you to follow, this time you don't need test.doc, it will populate then format it as you wanted.Hope it helps.#include <Word.au3> ; Create application object Local $oRange, $oWord = _Word_Create() ; Open the test document Local $oDoc = _Word_DocAdd($oWord) ; Set default alignment 0= Left, 1 = Centre, 2 = Right Local $wdAlignParagraphJustify = 0 ; Select start of doc as range $oRange = _Word_DocRangeSet($oDoc, -1) ; Insert text before selected range ^^ $vRange = $oDoc.Range $vRange.InsertBefore("I am line 1" & @CR & "I am line 2" & @CR & "I am line 3") ; Move line 1 $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 0, Default, 2) Local $wdAlignParagraphJustify = 2 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify ; Move line 2 $oRange = _Word_DocRangeSet($oDoc, 0, $wdParagraph, 1, Default, 2) Local $wdAlignParagraphJustify = 1 $oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify 1 blisszero reacted to this Share this post Link to post Share on other sites
Efo74 3 Posted July 8, 2015 goss34,this is just what I was trying to do,thank you for everything, you were very kind. Hide Efo74's signature Hide all signatures :rolleyes: Share this post Link to post Share on other sites
goss34 1 Posted July 8, 2015 No problem Efo, its nice to be able to help someone else for a change rather than someone always helping me Share this post Link to post Share on other sites
blisszero 0 Posted April 24, 2018 this topic helped me a lot to clarify some problems that had been, leaving just another reference for future searches #include <Word.au3> ;~ criar Word oculto(false) / create hidden Word document (false) $oWord = _Word_Create(False) ;~ Adicionar documento criado para edição / Add document created for editing $oDoc = _Word_DocAdd($oWord) ; Usar a seleção atual / Use current selection $oRange = _Word_DocRangeSet($oDoc, 0) ; Inserir Texto / Insert Text $oRange.Insertafter(ClipGet()) ;~ Formatação do texto / Formatting text $oRange.ParagraphFormat.Alignment = 9 ; Left = 0, Center = 1, Right = 2, Justify = 3, ThaiJustify = 9 $oRange.Font.Name = "Century Gothic" $oRange.Font.Size = 12 $oRange.Font.ColorIndex = 1 ; https://i-msdn.sec.s-msft.com/pt-br/vba/excel-vba/articles/images/colorin_za06050819.gif ;substituir duplo ou triplo pulo de linha / replace double or triple line jump _Word_DocFindReplace($oDoc, "^13^13^13", "^p", Default, Default, Default, Default, True) _Word_DocFindReplace($oDoc, "^13^13", "^p", Default, Default, Default, Default, True) ; Salvar / Save _Word_DocSaveAs($oDoc, @ScriptDir & "\coco.doc") ; fechar COM Word / close and quit word doc _Word_DocClose($oDoc) _Word_Quit($oWord) tks any \/ Share this post Link to post Share on other sites