viptnn

How to Edit Table Microsoft Word

11 posts in this topic

anyone know how to edit available table at word: add row or fill data to cell. I have searched but not found

Share this post


Link to post
Share on other sites



It depends ...

You could use the Word UDF that comes with AutoIt. Use function _Word_DocTableRead to retrieve the current table, then modify the array and rewrite the table using function _Word_DocTableWrite.
As the functions only retrieve the text, formatting will be lost.

Another possible way is to use MS COM interface to Word. But this will take a bit more time and effort.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It's easy with MS COM. read this for writing text

https://msdn.microsoft.com/en-us/library/tkf9d64e.aspx

And this for adding rows and cols

https://msdn.microsoft.com/en-us/library/2dw39e8e.aspx

 

1 person likes this

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

If you have problems translating the code to AutoIt please post your questions here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If you have problems translating the code to AutoIt please post your questions here.

Autoit is the first language i study, so please teach me how to translate VBA to autoit.

Me.Application.ActiveDocument.Tables.Item(1).Rows.Add()
With Me.Tables.Item(1).Cell(1, 1).Range
    .Text = "Name"
    .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
End With

Share this post


Link to post
Share on other sites

@viptnn ,

First of all, you need to create or get the word's com object. Use "ObjCreate" or "ObjGet" function for that. Read the help file for more details.

Remember, When using ObjCreate, you are going to create a new instance of word and when using ObjGet, your trying to connect the already opened word instance. 

And when you create or get the object, then you can use it like this for the above given code.

For example, this is the vb code 

Me.Application.ActiveDocument.Tables.Item(1).Rows.Add()

You can write it like this

Local $oWord = ObjGet("","Word.Application")

$oWord.ActiveDocument.Tables.Item(1).Rows.Add()

So simple. And do not forget to check the constants for WordConstants.au3 in include folder.

1 person likes this

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

To create the Word COM object and to open the document you can use _Word_Create, _Word_DocOpen from the Word UDF that comes with AutoIt.
The UDF makes things a bit easier and comes with error checking already included.

2 people like this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

For example, this is the vb code 

Me.Application.ActiveDocument.Tables.Item(1).Rows.Add()

You can write it like this

Local $oWord = ObjGet("","Word.Application")

$oWord.ActiveDocument.Tables.Item(1).Rows.Add()

So simple. And do not forget to check the constants for WordConstants.au3 in include folder.

Its look like very easy, i can do with second case. Thank you so much 

Dim $oDoc = $oWord.ActiveDocument

With $oDoc.Tables.Item(1).Cell(1, 1).Range
    .Text = "Name"
    .ParagraphFormat.Alignment = "Word.WdParagraphAlignment.wdAlignParagraphRight"
EndWith

Share this post


Link to post
Share on other sites

Autoit does not support the VB way to use application related constants. Try:

; Enumeration taken from: https://msdn.microsoft.com/en-us/library/ff835817%28v=office.14%29.aspx
Global $wdAlignParagraphRight = 2 ; Right-aligned
Global $oDoc = $oWord.ActiveDocument
With $oDoc.Tables.Item(1).Cell(1, 1).Range
    .Text = "Name"
    .ParagraphFormat.Alignment = $wdAlignParagraphRight
EndWith

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water,  I think these constants are already declared in WordConstants.au3. So inclusing that file is the right way, is it ?


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

The Word UDF only has those constants defined in WordConstants.au3 which are used as parameters by one of the functions of the Word UDF.
Else WordConstants.au3 would have become way too big.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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