Excel - Open/Create workbook
Declaration
<AMEVENTLOG MESSAGE="text (message to log)" TYPE="text (options)" />
Description: Creates a Microsoft Excel workbook and attaches a session name for use in other Excel actions.
Practical Usage
Commonly used to create a new Microsoft Excel document and associate it with a session to allow other Excel actions to be performed by linking those actions to the specified session. The newly created workbook automatically becomes the active workbook. Any modifications made to the workbook is saved to memory and not saved to the hard disk until the Close Workbook action is used or if the workbook is saved manually by a user.
General Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Workbook |
Text |
Yes |
(Empty) |
WORKBOOK="c:\file.xls" |
The path and file name of the Excel workbook that should be created. NOTE: The file will initially be saved to memory. It will not be saved to the hard disk until the file is saved either manually or by using the Close Workbook action. |
Session Name |
Text |
Yes |
Sheet1 |
SESSION="mySession" |
The session name to establish and identify the newly created document in subsequent Excel steps. This allows several Excel files to be open simultaneously. If only working with one document at a time, this value should not be changed from it's default. |
Create from Template |
Text |
No |
(Empty) |
TEMPLATE= "c:\temp\template.xlt" |
If enabled, specifies that a template should be used when creating the file. Enter the path and file name of the desired template in the provided text box. Excel templates have the file extension .xlt. |
Workbook is invisible |
Yes/No |
No |
No |
VISIBLE="NO" |
If enabled, specifies that the Microsoft Excel Window will not be displayed and all processing will occur in the background. This option should be left unchecked during task construction and debugging, but enabled for production. The workbook is visible by default. |
Overwrite if workbook already exists |
Yes/No |
No |
No |
OVERWRITE="YES" |
If enabled, specifies that if the file specified in the Workbook parameter already exists, it will be overwritten. |
Description tab - A custom description can be provided on the Description tab to convey additional information or share special notes about a task step.
Error Causes tab - Specify how this step should behave upon the occurrence of an error. (Refer to Task Builder > Error Causes Tab for details.)
On Error tab - Specify what AWE should do if this step encounters an error as defined on the Error Causes tab. (Refer to Task Builder > On Error Tab for details.)
Example
The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.
This sample task demonstrates the use of various Excel actions. Below describes each step of the task, including the action used and details about that action.
-
Create Workbook Action - Create new Excel workbook "C:\Temp\sampledoc.xls". Overwrite file if it already exists.
-
Add Worksheet Action - Add new Excel worksheet "My New Sheet" to workbook open in session "ExcelSess1". New worksheet will be the last one of the workbook.
-
Activate Worksheet Action - Activate Excel worksheet "My New Sheet" in workbook open in session "ExcelSess1".
-
Set Cell Action - Write text "Set this data here" in Excel cell located at row:1 and column:1.
-
Pause Action - Pause task for 3 seconds.
-
Set Cell Action - Write text "and this here" in Excel cell located at row:2 and column:1.
-
Pause Action - Pause task for 3 seconds.
-
Close Workbook Action - Close Excel workbook. Do not save workbook before closing.
<AMEXCELCREATEWORKBOOK WORKBOOK="c:\sampledoc.xls" OVERWRITE="YES" /> <AMEXCELADDWORKSHEET WORKSHEETNAME="My New Sheet" LASTWORKSHEET="YES" /> <AMEXCELACTIVATEWORKSHEET WORKSHEET="My New Sheet" /> <AMEXCELSETCELL NEWVALUE="Set this data here" CELLROW="1" CELLCOLUMN="1" /> <AMPAUSE ACTION="waitfor" SCALAR="3" /> <AMEXCELSETCELL NEWVALUE="and this here" CELLROW="2" CELLCOLUMN="1" /> <AMPAUSE ACTION="waitfor" SCALAR="3" /> <AMEXCELCLOSEWORKBOOK SAVE="NO" />