Jump to content
Sign in to follow this  
water

Update the Word UDF that comes with AutoIt (former WordEX thread)

Recommended Posts

water

New versions of Microsoft Office have been released since the last changes were made to the Word UDF. New file types and new functions need to be supported.
This updated version supports Word 2003 up to Word 2010. The latest version of AutoIt is needed to use the latest COM error handler.
Some rarely used functionality has been removed, new functions have and will be added.
The attached PDF shows what's different between Word.au3 and WordEX.au3
You'll find examples for every function ready to run.

Please tell me what you think, about missing functions etc.

2012-07-31 - Version 1.0 - Downloads: 89

First release


2012-08-23 - Version 1.1 - Downloads: 26

New Functions:
  • _Word_DocTableRead: Reads a Word table into a 2D-array
  • _Word_DocTableWrite: Writes a 1D or 2D-array to a Word table

Removed Functions:

  • _Word_MacroRun: Just called the Run method, nothing else, hence removed

 

2012-08-26 - Version 1.2 - Downloads: 277

New Functions:
  • _Word_DocFind: Run or repeat a find operation

 

2012-12-29 - Version 1.3 - Downloads: 937

General:
  • Enhanced error checking
  • Enhanced documentation

New Functions:

  • _Word_DocExport: Exports the document or a range as PDF or XPS

Changed Functions:

  • _Word_Create: Parameter $bForceNew added to create a new instance even if another already exists
  • _Word_DocClose: Defaults for parameters $iSaveChanges and $iOriginalFormat changed to minimize need for user intervention
  • _Word_DocLinkAdd: Default for parameters $oAnchor, $sAddress, $sSubAddress, $sScreenTip, $sTextToDisplay and $sTarget changed from "" or 0 to keyword Default
  • _Word_DocLinkGet: Default for parameter $iIndex changed from -1 to keyword Default

Removed Functions:

  • Unneeded helper functions: CentimetersToPoints, InchesToPoints, LinesToPoints, PicasToPoints, PointsToCentimeters, PointsToInches, PointsToLines, PointsToPicas

 

2013-07-28 - This download page is no longer needed - the rewritten Word UDF is now part of the latest beta version!

Edited by water
  • Like 2

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

To do:

  • _Word_DocTableFormat: Format a table, columns or rows
To check:
  • Formatting of a range (font, style ...)
  • Shapes
  • Lists
Done:
  • _Word_DocTableWrite: Write a 1D or 2D array to a Word table
  • _Word_DocTableRead: Read the content of a Word table to an array
  • _Word_DocFind: Extended search function
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Myicq

Would be nice to see more functions included, f.ex to add shapes.

In that relation, it would be real nice to download and insert all the many many enumerations that Word/Office uses, into a UDF, and possibly also with auto-complete in Scite. (that's my wish for serious Office COM work)

For expansion of this, would you accept change proposals, or just requests ?


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites
water

I will have a look at shapes. Which functionality do you need?

Enumerations:

I don't think it is sensible to include all enumerations - the list would be too long. WordEXConstants contains all enumerations referenced by a function of the WordEX UDF. I think auto-complete in SciTE isn't very realistic at the moment. But MSDN isn't far away.

I accept all kinds of change proposals, requests ... whatever. You post what you'd like to see and then we discuss if it makes sense to include it ^_^


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Version 1.1 has been released!

Have fun testing!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ajit

@water

Thanks for the UDF, particularly for the new _Word_DocRangeSet.

Look forward to your future releases.

Regards

Ajit

Share this post


Link to post
Share on other sites
water

Is there anything you would like to see in the Word UDF?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Myicq

I will have a look at shapes. Which functionality do you need?

I came to this yesterday because I needed to create a test document where placement of shapes on the page was essential (for a test pattern used at work). I gave up the menu hell in Word and ended up programming a macro for it. But it would have been nice to use AutoIT for the purpose, since the job was perfect for scripting.

I think the basic shapes should be enough, although actually there are only two: shape and inlineshape. In your script you only have inlineshape. Difference is that shape hovers over text, and is page-related. inlineshape is text-related, like a char.

There are some 150 different types (according to enumeration), but for most 5-10 basic shapes are used.

Something like

$myShape = _Word_Shape_Add($myDoc, $WdShapeTypeRectangle, 100, 120, 10, 10)
_Word_Shape_Set_Color($myShape, $WdWhite, $WdBlack)

There are MANY options to shapes, so I will have to look a bit deeper into this matter. There are also some definitions to do, f.ex measurements in points/inch/mm/cm/.. ? Insert in document or range ?

Enumerations:

I don't think it is sensible to include all enumerations - the list would be too long. WordEXConstants contains all enumerations referenced by a function of the WordEX UDF. I think auto-complete in SciTE isn't very realistic at the moment. But MSDN isn't far away.

Yes, you are probably right. I actually did not see you already included many of them, my bad.

I accept all kinds of change proposals, requests ... whatever. You post what you'd like to see and then we discuss if it makes sense to include it ^_^

Is discussion about your script HERE or in the general forum ? I mean, Example scripts is for showing your script, not requesting features - or ? I am in doubt about forum rules on that point, who/where do I ask ?

But anyway, a few things:

  • Shape and InlineShape
  • Adding styles to new documents (do not have to be globally stored), and modifying style definitions. I tried to do that myself and failed badly.
  • Working with variables (essentially metadata, MSWord allows up to 65280 unicode chars per var.), and changing document properties
  • Tables (you already have that in the pipeline)

Think this will be a great UDF :)


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites
water

I think the Word UDF isn't and can never be one of the UDFs that isolates the user completely from the object model. He will have to cope with methods and properties.

The UDF will only have basic functions - everything else has to be done by the user (see the example script _Word_RangeSet.au3 where the UDF makes handling the range a bit easier, but what to do with the range is up to the user and needs some knowledge of the object model).

Shapes:

I will have a look at shapes and if it makes sense to add them to the UDF. The functions should be useful to a lot of people.

Styles:

Maybe later. For now I think we should add the simple things

Variables, document properties:

We removed functions to get/set properties of a document or the Word application because it is only a single line when directly accessing COM

If you have a problem you need to solve post here so we can discuss if this can be solved with a UDF function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ajit

@water,

Would it be possible to have a function to search for a word which then highlights the word (just like Ctrl+F in word) the first occurrence of the word.

_Word_DocFindReplace just replaces the word in one go.

Also if possible the GoTo functions (Ctrl+G) like GoTo Line, Page, Section (i am not very sure if _Word_DocRangeSet can accomplish some of these tasks).

Also if file menu show/hide, word window size and placement of window could be added.

Regards,

Ajit

Share this post


Link to post
Share on other sites
water

Hi Ajit,

an extended search function is in the pipeline. You will be able to step through the search results and do whatever you need to do with each result.

_Word_DocRangeSet should be able to do what you need (I hope). Just use the correct units from the wdUnit enumeration.

I'm not sure if window handling (size, position) should be part of the Word UDF. Because window handling is one of the core duties of AutoIt itself, right?

Regards

water


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ajit

Water,

Thanks for the quick reply.

Look forward to the extended search function. Will be back with more queries.

Regards,

Ajit

Share this post


Link to post
Share on other sites
water

I have an extended find function now that lets you search forward and backward in a specified range.

It doesn't let you wrap the search though. That means you can't continue to search at the beginning of the range when you have reached the end and vice versa.

Might this be a problem for someone?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Version 1.2 has been released!

Extended Find function (_Word_DocFind) added!

Have fun testing!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ajit

Water,

Thanks for _Word_DocFind. Got to play with it.

Regards

Ajit

Share this post


Link to post
Share on other sites
water

176 downloads of the latest version - but no error reports, no questions, no complaints :think:

Do you think the UDF is already good enough to replace the Word UDF that comes with AutoIt?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

202 downloads of the latest version - but no error reports, no questions, no complaints :think:

Do you think the UDF is already good enough to replace the Word UDF that comes with AutoIt?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Thanks, glad you like the enhanced UDF :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jury

water,

I've use the old _WordDocPropertySet in some of my programs now because of the variety of MS Word versions the programs apply to I'm using the WordEX 1.2 UDF. Is there any reason why I can't include WordEX.au3 and Word.au3 both in order to give me access to _WordDocPropertySet? It doesn't seem to work for me when I use both.

I see that the equivalent has been removed from your program along with _WordDocPropertySet . Does this mean that when/if WordEX 1.2 UDF is adopted these the removed functions will no longer be available?

Thanking you for any information,

jury

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Similar Content

    • lavascript
      By lavascript
      I have a Word document containing a 9-column table where row 1 is the column headers. My goal is to read the table into a 2d array, remove some rows, update some fields, and add a few rows to the end. The resulting array will likely be a different length. Next, I want to write the data back into the table. If it's easier, I can write the data to a new document from a template containing the same table header with a blank 2nd row.
      Here's my early attempt:
      Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, $sFile) Local $aData = _Word_DocTableRead($oDoc, 1) $aData[3][5] = "Something else" Local $oRange = _Word_DocRangeSet($oDoc, 0) $oRange = _Word_DocRangeSet($oDoc, $oRange, $wdCell, 9) _Word_DocTableWrite($oRange,$aData) This, unfortunately, writes the entire array into the first cell of row 2. What am I doing wrong?
       
    • Subz
      By Subz
      Backstory:
      Our Microsoft Office Templates shared folder was changed from a DFS share to an Isilon share. example:
      Old Server: \\Domain.com\Office\Templates
      New Server: \\Templates.domain.com\Office\Templates
      The team making the changes overlooked that several hundred thousand documents, had been attached to the old template documents.  So when you open a document which has been attached, it will take a couple of minutes to open, while it tries to locate the old server path.  I've been asked to come in and fix it, so after several hours found that the data is being held in document.zip\word\_rels\settings.xml.rels, I now need to replace the old server path with the new server path.  I didn't want to use dom as that would take too long and found a tool wtc https://github.com/NeosIT/wtc which  works perfectly, takes about 8 minutes to scan a single directory with 4000 documents and fix them.  The problem is the documents are all held on sharepoint and they want to retain the file timestamp, which is easy enough, but they also don't want to keep the "Modified By" apparently they don't like seeing all the documents appearing as "Modified by: Subz"  Anyone know of way to retain the "Modified By" info,
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • Benandro
      By Benandro
      Hello,
      im working on a Script that should change a high amount of Word Templates at once.
      Target is to open each Templatefile (.dotx) in a specific folder and do the following steps:
      Add a page break at the end of the document (works) Add a text on the created Page (works) Change the headerstyle to blank for the new page and the following (missing) Add a heading between two specific headings (missing) Can please someone help me to add the 2 functions to the script?
       
      #include <word.au3> #include <File.au3> #include <array.au3> ; wdGoToDirection Const $wdGoToNext = 2 ; wdGoToItem Const $wdGoToPage = 1 ; Created a logfile for tracking/error reporting on my local desktop, though anywhere would work. Needs to be changed or it will error. Global $LogFile = FileOpen("c:\logfiles\test.log", 1) ; This is the network path, change it or this will error as it is. ListFiles ("D:\Templates\") Global $loopend=$aFileList[0] ; Creates an instance of Word for the program to use. Logs any errors associated. Global $oWord = _Word_Create(False, False) If @error <> 0 Then Exit _FileWriteLog($LogFile, "Error creating a new Word application object. @error = " & @error & ", @extended = " & @extended & @crlf) If @extended = 1 Then _FileWriteLog ($LogFile, "MS Word was not running when _Word_Create was called." & @CRLF) Else _FileWriteLog ($LogFile, "MS Word was already running when _Word_Create was called." & @CRLF) EndIf ; Logs and begins loop _FileWriteLog ($LogFile, "Beginning Loop." & @CRLF) For $looper = 1 to $loopend Step +1 _FileWriteLog ($LogFile, "Modifying file: " & $aFileList[$looper], " ") OpenAndModify ("D:\Templates\" & $aFileList[$looper]) Next ; Closes instance of Word _Word_Quit ($oWord) _FileWriteLog ($LogFile, "Program Completed.") ; Begins Function section ; Two functions, Listfiles and OpenAndModify Func ListFiles($FolderPath) ; Function puts all files in the network folder into an array. Logs any errors. _FileWriteLog ($LogFile, "Getting File Information for: " & $FolderPath & @crlf) Global $aFileList = _FileListToArray($FolderPath, "*") If @error = 1 Then _FileWriteLog($LogFile, "Path was invalid." & @crlf) EndIf If @error = 4 Then _FileWriteLog ($LogFile, "No file(s) were found." & @crlf) EndIf EndFunc Func OpenAndModify ($sDocument) ; Function opens file and changes the Page Setup ; Opens the Document Local $oDoc = _Word_DocOpen ($oWord, $sDocument, Default, Default, Default) If @error <> 0 Then _FileWriteLog ($LogFile, "Error opening " & $sDocument & " @error = " & @error & ", @extended = " & @extended & @crlf) & Exit ; Changes Tray Settings ;$oDoc.PageSetup.FirstPageTray = 0 ;$oDoc.PageSetup.OtherPagesTray = 0 ; Add a link to the end of the document and set parameters ; ScreenTip and TextToDisplay Local $oRange = _Word_DocRangeSet($oDoc, -2); Go to end of document $oRange.InsertBreak($wdPageBreak) ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", "Inserted a break.") $oRange.Text = "«Text»" ; Add a space at the end of the document $oRange = _Word_DocRangeSet($oDoc, -2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _ "Error adding a link to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", "Baustein wurde an das Ende des Dokuments eingefügt.") ; Saves the document _Word_DocSave($oDoc) _FileWriteLog ($LogFile, "Modification of" & $sDocument & " complete." & @CRLF) EndFunc  
    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
×