Efo74 Posted July 6, 2015 Share Posted July 6, 2015 Hello,I would like to know if there is a way to justify text in Word via Autoit.Tahnk you :rolleyes: Link to comment Share on other sites More sharing options...
water Posted July 6, 2015 Share 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 232showtime 1 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 More sharing options...
Efo74 Posted July 6, 2015 Author Share Posted July 6, 2015 Thank you, now I will try:-) :rolleyes: Link to comment Share on other sites More sharing options...
Efo74 Posted July 6, 2015 Author Share 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 :rolleyes: Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 6, 2015 Moderators Share 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 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Efo74 Posted July 7, 2015 Author Share 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") :rolleyes: Link to comment Share on other sites More sharing options...
goss34 Posted July 7, 2015 Share 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 Link to comment Share on other sites More sharing options...
Efo74 Posted July 7, 2015 Author Share Posted July 7, 2015 Sorry, but it does not work,Word 2013 opens with no blank page ... nothing appear :rolleyes: Link to comment Share on other sites More sharing options...
goss34 Posted July 7, 2015 Share 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. Link to comment Share on other sites More sharing options...
goss34 Posted July 7, 2015 Share 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 Link to comment Share on other sites More sharing options...
water Posted July 7, 2015 Share Posted July 7, 2015 Will test 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 More sharing options...
Efo74 Posted July 7, 2015 Author Share 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) :rolleyes: Link to comment Share on other sites More sharing options...
water Posted July 7, 2015 Share 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. 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 More sharing options...
Efo74 Posted July 8, 2015 Author Share Posted July 8, 2015 Thant you,today I am out of office, but Tomorrow i will try using $oRange.InsertAfterI keep you updated :rolleyes: Link to comment Share on other sites More sharing options...
goss34 Posted July 8, 2015 Share 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 blisszero 1 Link to comment Share on other sites More sharing options...
Efo74 Posted July 8, 2015 Author Share Posted July 8, 2015 goss34,this is just what I was trying to do,thank you for everything, you were very kind. :rolleyes: Link to comment Share on other sites More sharing options...
goss34 Posted July 8, 2015 Share 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 Link to comment Share on other sites More sharing options...
blisszero Posted April 24, 2018 Share 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 \/ 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