Excel UDF: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
(Created page with "{{WIP}} The Excel UDF offers functions to control and manipulate Microsoft Excel workbooks. == Script breaking changes after AutoIt version 3.3.10.2. == New versions of Micros...")
 
mNo edit summary
Line 13: Line 13:
The following list shows the old/new function/parameter name (a "-" is shown if the function/parameter has been removed) and some example scripts how to mimic the behaviour of the "old" UDF. If there is no entry for a removed function/parameter then there is no need for this functionality.
The following list shows the old/new function/parameter name (a "-" is shown if the function/parameter has been removed) and some example scripts how to mimic the behaviour of the "old" UDF. If there is no entry for a removed function/parameter then there is no need for this functionality.


=== Function _WordCreate/_Word_Create ===
=== Function -/_Excel_Open ===
It's mandatory now to call function _Word_Create. You could use _WordCreate or _WordAttach in the old Word UDF.
It's mandatory now to call function _Excel_Open. This function didn't exist in the old UDF.
@extended is set if Word was already running.
@extended is set if Excel was already running.


==== Parameter $s_FilePath/- ====
==== Parameter $s_FilePath/- ====
Optional parameter to specify the file to open upon creation.
Optional parameter to specify the file to open upon creation.
Use _Word_DocOpen or _Word_DocAdd now.
Use _Word_DocOpen or _Word_DocAdd now.
=== Function _WordDocPropertyGet/- ===
Retrieves builtin document properties.
Word object model reference on MSDN for Word 2010:
* [http://msdn.microsoft.com/en-us/library/ff195105%28v=office.14%29.aspx WdBuiltInProperty Enumeration]
Example code:<syntaxhighlight lang="autoit">
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test.doc")
Global $wdPropertyAuthor = 3
Global $sAuthor = $oDoc.BuiltInDocumentProperties($wdPropertyAuthor).Value ; Retrieves the Author of the document
</syntaxhighlight>
=== Function _WordDocPropertySet/- ===
Sets builtin document properties.
For links to the Word object model reference on MSDN see function _WordDocPropertyGet.
Example code:<syntaxhighlight lang="autoit">
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test.doc")
Global $wdPropertyAuthor = 3
$oDoc.BuiltInDocumentProperties($wdPropertyAuthor).Value = "PowerUser" ; Sets the Author of the document
</syntaxhighlight>
=== Function _WordErrorHandlerDeRegister/_DebugCOMError ===
The default COM error handler has been moved to the Debug UDF. See _WordErrorHandlerRegister for details.
=== Function _WordErrorHandlerRegister/_DebugCOMError ===
The default COM error handler has been moved to the Debug UDF. But you can still create a custom COM error handler by using ObjEvent.
Example code:
<syntaxhighlight lang="autoit">
#include <Debug.au3>
_DebugSetup("Word Debug Window", True, 1, "", True)
_DebugCOMError(1) ; Register a default COM error handler to grab Word COM errors and write the messages to the Debug window
; Do Word processing here
_DebugCOMError(0) ; DeRegister the default COM error handler
</syntaxhighlight>
=== Function _WordErrorNotify/- ===
The Word UDF no longer creates text error messages and writes them to the Console.
You need to check the macros @error and @extended after you called a function. The returned values are documented in the help file.
=== Function _WordMacroRun/- ===
A macro can now be run by a single line.
Example code:
<syntaxhighlight lang="autoit">
Global $oWord = _Word_Create()
Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test.doc")
$oWord.Run("macro_name")
</syntaxhighlight>
=== Function _WordPropertyGet/- ===
Retrieves application and document properties. Many of the properties for the Options object correspond to items in the Options dialog box.
Word object model reference on MSDN for Word 2010:
* [http://msdn.microsoft.com/en-us/library/ff841712%28v=office.14%29.aspx Word Application properties]
* [http://msdn.microsoft.com/en-us/library/ff821122%28v=office.14%29.aspx Word properties for the Options object]
Example code:<syntaxhighlight lang="autoit">
Global $oWord = _Word_Create()
$bVisible = $oWord.Visible ; Returns True when the Word application is visible, else False
$bUpdatePrint = $oWord.Options.UpdateFieldsAtPrint ; True if Microsoft Word updates fields automatically before printing a document
</syntaxhighlight>
=== Function _WordPropertySet/- ===
Sets application and document properties. Many of the properties for the Options object correspond to items in the Options dialog box.
For links to the Word object model reference on MSDN see function _WordPropertyGet.
Example code:<syntaxhighlight lang="autoit">
Global $oWord = _Word_Create()
$bVisible = $oWord.Options.SaveInterval = 5 ; Sets Word to save AutoRecover information for all open documents every five minutes
</syntaxhighlight>


[[Category:UDF]]
[[Category:UDF]]

Revision as of 19:17, 23 March 2014

This page is still a work in progress.

The Excel UDF offers functions to control and manipulate Microsoft Excel workbooks.

Script breaking changes after AutoIt version 3.3.10.2.

New versions of Microsoft Office have been released since the last changes were made to the Excel UDF. New file types and new functions needed to be supported, hence the UDF was complete rewritten.

Some functions/parameters have been removed or renamed, new functions/parameters have been added. A detailed list of changes can be found here.

General

All function names have been changed from _Excel* to _Excel_*.

@extended no longer contains the number of the invalid parameter. The code returned in @error tells exactly what went wrong.

The following list shows the old/new function/parameter name (a "-" is shown if the function/parameter has been removed) and some example scripts how to mimic the behaviour of the "old" UDF. If there is no entry for a removed function/parameter then there is no need for this functionality.

Function -/_Excel_Open

It's mandatory now to call function _Excel_Open. This function didn't exist in the old UDF. @extended is set if Excel was already running.

Parameter $s_FilePath/-

Optional parameter to specify the file to open upon creation. Use _Word_DocOpen or _Word_DocAdd now.