Excel - Add Worksheet
Declaration
<AMEXCEL ACTIVITY="add_worksheet" WORKBOOK="text" OPENPASSWORD="encrypted text" MODIFYPASSWORD="encrypted text" INVISIBLE="YES/NO" WORKSHEETNAME="text" SHEETTYPE="text (options)" />
Description: Adds a new worksheet to a workbook in an established Excel session.
Practical Usage
Used to create a new worksheet to be added to an Excel document that was previously opened or created using the Open/Create workbook activity.
Resource Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Resource |
|
|
|
|
Indicates where the source Excel document should originate from. This is a design mode parameter used only during task construction and configuration, thus, comprises no markup. The available options are:
|
Session |
Text |
Yes if Resource is set to Session |
Excelsession1 |
SESSION="mySession" |
The name of an existing session to associate this activity with. This parameter is active only if the Resource parameter is set to Session. |
Get document by |
Text (options) |
Yes if Resource is set to File |
Open |
|
Specifies whether this activity will be performed on an existing Excel document or on a new one. This parameter is active only if the Resource parameter is set to File. The available options are:
|
File name |
Text |
Yes |
(Empty) |
WORKBOOK="C:\Temp\file.xls" |
If the Get document by parameter is set to Open, specifies the path and filename of the Excel document in which to open. If the Get document by parameter is set to Create, specifies the path and filename of the Excel document in which to create. |
Application is invisible |
Yes/No |
No |
No |
VISIBLE="NO" |
If set to YES, specifies that the Excel window will not be displayed and all processing will occur in the background. This option should be set to NO during task construction and debugging but can be set to YES for production. The workbook is visible by default. |
Password to open (optional) |
Text |
No |
(Empty) |
OPENPASSWORD="encrypted" |
The password required to open the Excel document if it is password protected. This parameter is active only if the Get document by parameter is set to Open. |
Password to modify (optional) |
Text |
No |
(Empty) |
MODIFYPASSWORD="encrypted" |
The password required to modify the Excel document if it is password protected. This parameter is active only if the Get document by parameter is set to Open. |
Create from template |
Text |
No |
No |
WORKBOOKTEMPLATE="C:\Temp\file.xls" |
If enabled, specifies the path and filename of a template file that already has preferred formatting in which to base the new workbook on. A template can include formatting, styles, standardized text such as page headers and row and column labels, formulas, macros and custom toolbars. This parameter is active only if the Get document by parameter is set to Create. It is disabled by default. |
Overwrite if workbook already exists |
Yes/No |
No |
No |
OVERWRITE="yes" |
If set to YES, the newly created workbook will overwrite an existing workbook with the same name, If set to NO, an error will occur during runtime as a result of a matching filename. This parameter is active only if the Get document by parameter is set to Create. |
On completion |
Text (options) |
No |
Save |
|
Specifies what to do with the document upon completion of this activity. The available options are:
|
Overwrite if workbook already exists |
Yes/No |
No |
No |
OVERWRITEDESTINATION="YES" |
If set to YES, specifies that existing Excel files with matching names that exist in the destination will be overwritten. If set to NO, matching files will not be overwritten, however, a runtime error will occur as a result. Set to NO by default. |
Worksheet Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Sheet Type |
Text (options) |
No |
Worksheet |
SHEETTYPE="chart" |
The type of worksheet that should be added. The available options are:
|
Worksheet Name |
Text |
Yes |
(Empty) |
WORKSHEETNAME="c:\file.xls" |
The path and file name of the new worksheet that will be created. NOTE: Any subsequent actions performed on the worksheet will be saved to memory. The file will not be changed on the hard disk until it is saved either manually or with the use of the Close Workbook activity (with the Do not save changes parameter disabled). |
Insert worksheet before active one |
Yes/No |
No |
No |
LASTWORKSHEET="NO" |
If set to YES, the new worksheet will be added before the currently active worksheet |
Add worksheet at the end |
Yes/No |
No |
No |
LASTWORKSHEET="yes" |
If set to YES, the worksheet will be added after the active worksheet. |
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" />