Jump to content

Recommended Posts

Posted

Sure. Autoit comes with a Word UDF, Use function _Word_DocRangeSet to select the paragraph to justify.
Then use

$oRange.ParagraphFormat.Alignment = $wdAlignParagraphJustify

The WdParagraphAlignment enumeration can be found here: https://msdn.microsoft.com/en-us/library/bb237926(v=office.12).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

 

Posted

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 line

this is the second line

this is the third line

Thank you all for your support

:rolleyes:

Posted

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:

Posted

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

 

Posted

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.

Posted (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 = $wdAlignParagraphJustify

Text 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 by goss34
Posted

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

 

Posted

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:

Posted

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

 

Posted

Thant you,

today I am out of office, but Tomorrow i will try using $oRange.InsertAfter

I keep you updated

:rolleyes:

Posted

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

 

  • 2 years later...
Posted

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 \:D/

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...