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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

Version 1.1 has been released!

Have fun testing!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

Version 1.2 has been released!

Extended Find function (_Word_DocFind) added!

Have fun testing!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

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 (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

Thanks, glad you like the enhanced UDF :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
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

    • 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)

       
    • Jury
      By Jury
      I've failed to find an example of _Word_DocFindReplace which searches for formatted text (I'm looking for stand alone paragraph marks that are formatted other than normal i.e. Bold Italic, Underlined). 
      The reason being that when converting a Word document to html one of the main problems in the results is that a stand alone paragraph mark is converted to an html space that retains the formatting ...>&nbsp;<... thus showing up as a underline _  in a browser when it should be blank.  I've played around with the script and got it to at least un-bold  the first paragraph mark regardless if it was bold or not but I'd like to clear all formatting from any stand alone paragraph marks in the whole document.  Below is what I've done so far (not much more than in the help file I'm afraid) .  Way down at the bottom of the _Word_DocFindReplace  help  text is this parameter but without any examples to be found :
      $bFormat   [optional] True to have the find operation locate formatting in addition to or instead of the find text (default = False) #include <MsgBoxConstants.au3> #include <Word.au3> $processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\' Global $oWord = _Word_Create() Global $sTestfile = $processing & "Testing.docx" ConsoleWrite($sTestfile & @CRLF) Global $oDoc = _Word_DocOpen($oWord, $sTestfile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening file = '" & $sTestfile & "'" & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound = _Word_DocFind($oDoc, "^p", Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = False If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me  
    • anthonyjr2
      By anthonyjr2
      I'm using the Word UDF for the first time, and I'm having some trouble with _Word_DocFind(). There isn't really much talk around the forums about this so it's hard to find any support on the issue I'm having. Here's my code:
      #include <Word.au3> $listPath = @ScriptDir & "\AMCH OFFSET 042617.docx" $pWord = _Word_Create() $oWord = _Word_DocOpen($pWord, $listPath) Local $ctr = 0 Local $searchRange = _Word_DocFind($oWord, "Claim Number") If Not @error Then $ctr += 1 EndIf While ($searchRange <> 0) $searchRange = _Word_DocFind($oWord, "Claim Number", 0, $searchRange) If Not @error Then $ctr += 1 EndIf $searchRange.Select WEnd My problem is that it doesn't seem to find a match of the string on any page after the second. When I run the script, it just loops indefinitely on the second page. I can't post an example of the word document because it is medical data, but every page is basically the same and every page has the string I am looking for on it. Also I tried checking @error after doing a find and it is never set, so I don't think that's the problem.
×