Add Worksheet Action Icon

Add Worksheet

Declaration

<AMEXCELADDWORKSHEET SESSIONNAME="text" WORKSHEETNAME="text" LASTWORKSHEET="yes/no" TEMPLATENAME="text">

See Also

Activate Cell | Activate Worksheet | Add Worksheet | Cells to Dataset | Close Workbook | Create Workbook | Dataset to Cells | Get Active Cell | Get Active Worksheet | Get Cell | Open Workbook | Set Cell

Description

Adds a new Excel worksheet to a workbook in an established Excel session.

IMPORTANT: AutoMate's Excel actions use Microsoft's Excel automation engine to perform their work. Therefore, Microsoft Excel must be licensed and installed on the system in order for these actions to work.

Practical Usage

Used to create a new worksheet to be added to an Excel document that was previously created using the Create Workbook action or opened using the Open Workbook action.

NOTE: This action is only useful in conjunction with other Excel actions found in AutoMate. It is not possible to use Automate's Excel actions on a spreadsheet that was not opened by the Open Workbook action or created by the Create Workbook action.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Session Name

Text

Yes

ExcelSess1

SESSION="ExcelSess7"

The name of the session to associate with this Excel action. Numerous sessions can exist within a single task allowing several spreadsheets to be open simultaneously. If working with only one document, this can remain at the default name, which is Excelsess1.

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 action (with the Do not save changes parameter disabled).

Insert before... / Add worksheet at the end

Yes/No

No

No

LASTWORKSHEET="yes"

If Insert worksheet before active one is enabled, the new worksheet will be added before the currently active worksheet. If Add worksheet at the end is enabled, the worksheet will be added after the active worksheet. when working with the workbook, the Microsoft Excel Window will not be displayed (processing will occur in the background). Usually this option should be left unchecked when building/debugging, but enabled for production.

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.

Template Name

Text

No

(Empty)

TEMPLATE="c:\mytemplate.xlt"

The path and file name of a template that should be used when adding the worksheet. Excel Templates have the file extension .xlt. This parameter is available only if Specific template is selected from the Sheet Type parameter.

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane 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 Task 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 Task 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" />

 

↑ Top of Page