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.

IMPORTANT: Excel activities rely on Microsoft's Excel engine to perform their work,therefore, MS Excel must be licensed and installed on the system in order for these activities to function properly.

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:

  • File (default) - The source derives from an Excel file located on the system. This option is normally selected if only a single activity is required to complete the operation.

  • Session - The source Excel document is obtained from a pre-configured session created in an earlier step with the use of the Open/Create workbook activity. This option is normally selected if a combination of related activities are required to complete an operation. Consolidating several activities to a single session can eliminate redundancy. Moreover, a single task supports multi-session executions which can improve efficiency and speed up production.

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

  1. CONNECTBY="open_workbook"

  2. CONNECTBY="create_workbook"

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:

  • Open (default) - This activity will be performed on an existing document that will be opened during runtime.

  • Create - This activity will be performed on a new document to be created during runtime.

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

  1. SAVETYPE="save"
  2. SAVETYPE="save_as"
  3. SAVETYPE="do_not_save"

Specifies what to do with the document upon completion of this activity. The available options are:

  • Save - Save changes to the current location.

  • Save as - Save to the specified path and filename.

  • Do not save changes - Changes will not be saved.

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 (Default) - A new blank worksheet will be added to the workbook.

  • Chart - A new chart will be added to the workbook.

  • Macro - A new macro will be added to the workbook.

  • Dialog - A new dialog will be added to the workbook.

  • Specific template: A new template should be used when adding a worksheet to the workbook.

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.

  1. Create Workbook Action - Create new Excel workbook "C:\Temp\sampledoc.xls".  Overwrite file if it already exists.  

  2. 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.  

  3. Activate Worksheet Action - Activate Excel worksheet "My New Sheet" in workbook open in session "ExcelSess1".  

  4. Set Cell Action - Write text "Set this data here" in Excel cell located at row:1 and column:1.  

  5. Pause Action - Pause task for 3 seconds.  

  6. Set Cell Action - Write text "and this here" in Excel cell located at row:2 and column:1.  

  7. Pause Action - Pause task for 3 seconds.  

  8. 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" />