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.

NOTE: 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

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.

NOTE: This action is only useful in conjunction with other Excel actions.

Parameters

General Properties

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

Error Causes

On Error

Example

NOTE: 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" />

  ↑ Top of Page