Excel - Close workbook

Declaration

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

Related Topics    

Description

Closes the workbook previously opened or created by the Excel - Open/create workbook activity and ends the associated session.

IMPORTANT: Automate Desktop's Excel activities rely on Microsoft's Excel engine to perform their work, therefore, Excel must be installed and licensed on the computer to ensure proper functionality.

Practical usage

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

Parameters

Session

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.
On completion Text (options) No Save
  • SAVETYPE="save"
  • SAVETYPE="save_as"
  • 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 default location.
  • Save as - Save changes to the specified path and file name.
  • Do not save changes - Changes will not be saved.
File Text Yes, if On completion is set to Save as (Empty) DESTINATION="c:\temp\dest.xls" The path and file name of the file in which changes will be saved. Click the folder icon to open a standard Explorer dialog in order to navigate to the desired file or simply enter the path and file name in the provided text box.
Overwrite if workbook already exists Yes/No Yes, if On completion is set to Save as No OVERWRITE="YES" If selected, the newly created workbook will overwrite any workbook with the same name that exists in the destination. If disabled (default), an existing workbook with the same name will not be overwritten, however, an error will occur during runtime as a result of matching file names. This parameter is only active if the Get document by parameter is set to Create.

Description

Error Causes

On Error

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Description

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.  

Copy
<AMEXCEL SESSION="ExcelSession1" CONNECTBY="create_workbook" WORKBOOK="c:\sampledoc.xls" OVERWRITE="YES" />
<AMEXCEL ACTIVITY="add_worksheet" SESSION="ExcelSession1" WORKSHEETNAME="My New Sheet" LASTWORKSHEET="YES" />
<AMEXCEL ACTIVITY="activate_worksheet" SESSION="ExcelSession1" WORKSHEET="My New Sheet" />
<AMEXCEL ACTIVITY="set_cell" SESSION="ExcelSession1" NEWVALUE="Set this data here" CELLROW="1" CELLCOLUMN="1" />
<AMWAIT SCALAR="3" /><AMEXCEL ACTIVITY="set_cell" SESSION="ExcelSession1" NEWVALUE="and this here" CELLROW="2" CELLCOLUMN="1" /><AMWAIT SCALAR="3" />
<AMEXCEL ACTIVITY="close_workbook" SESSION="ExcelSession1" SAVETYPE="do_not_save" />