Excel - Close workbook

Declaration

<AMEXCEL ACTIVITY="close_workbook" SESSION="text" SAVETYPE="text (options)" DESTINATION="text" OVERWRITEDESTINATION="YES/NO" />

Description: Closes a workbook previously created or opened in an established Excel session. If modifications have been made, the document will be saved when closed.

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

Mainly used to save and close an Excel document that was modified with prior Excel steps and ends the associated session.

NOTE: This action is only useful in conjunction with other Excel actions. It is not possible to use 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 session name to identify which document should be closed from prior Excel steps. Numerous sessions can exist within a single task allowing several Excel documents to be open simultaneously. If working with only one document, this can remain at the default session name, which is Excelsess1.

Do not save changes

Yes/No

No

No

RESULTDATASET="datasetname"

If set to YES, the document should be closed but not saved. The default behavior is to save the document when it is closed.

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