Excel - Get active worksheet

Declaration

<AMEXCEL ACTIVITY="get_worksheet" SESSION="text" CONNECTBY="text (options)" WORKBOOK="text" OPENPASSWORD="text (encrypted)" MODIFYPASSWORD="text (encrypted)" VISIBLE="YES/NO" WORKBOOKTEMPLATE="text" OVERWRITE="YES/NO" SAVETYPE="text (options)" DESTINATION="text" OVERWRITEDESTINATION="YES/NO" WORKSHEETINDEXVARIABLE="text" WORKSHEETNAMEVARIABLE="text" />

Related Topics    

Description

Retrieves the name or index of the currently active worksheet in an established Excel session and populates either or both of two variables, one for the worksheet name and the other for the index.

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

Used to find the currently active worksheet in a Microsoft Excel document that was opened or created in a previous step by the Excel - Open/create workbook activity. The active worksheet (also called spreadsheet) is the primary document that you use in Excel to store and work with data. A worksheet consists of cells that are organized into columns and rows; a worksheet is always stored in a workbook.

NOTE: If a worksheet has been protected, you may not be able to select cells or their contents.

Parameters

Resource

Property Type Required Default Markup Description
Resource --- --- --- --- Indicates where the source Excel document should originate from. This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes. 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 Excel - 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 only active if the Resource parameter is set to Session.
Get document by Text (options) Yes, if Resource is set to File Open
  • CONNECTBY="open_workbook"
  • 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\fileName.xls" If the Get document by parameter is set to Open, specifies the path and file name of the Excel document in which to open. If the Get document by parameter is set to Create, specifies the path and file name of the Excel document in which to create.
Application is invisible Yes/No No No VISIBLE="NO" If selected, specifies that the Excel window will not be displayed and all processing will occur in the background. This option should be disabled during task construction and debugging but can be selected 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 selected, specifies the path and file name 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 only active if the Get document by parameter is set to Create ( disabled by default).
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 to the specified path and file name.
  • Do not save changes - Changes will not be saved.
File Text Yes, if On completion parameter 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. This parameter is active only if the On completion parameter is set to Save as.
Overwrite if workbook already exists Yes/No Yes, if On completion parameter is set to Save as No OVERWRITE="YES" If selected, the saved 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 active only if the On completion parameter is set to Save as.

Worksheet

Property Type Required Default Markup Description
Populate variable with worksheet name Text No (Empty) WORKSHEETNAMEVARIABLE="theName" If enabled, specifies the name of an existing variable to be populated with the name of the active worksheet. If this parameter is disabled, a value is required in the Populate variable with worksheet index parameter.
Populate variable with worksheet index Number No (Empty) WORKSHEETINDEXVARIABLE="theIndex" If enabled, specifies the name of an existing variable to be populated with the index of the active worksheet. An index is a sequential number assigned to a sheet, based on the position of its sheet tab (counting from the left) among sheets of the same type. If this parameter is disabled, a value is required in the Populate variable with worksheet name parameter.

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 gets an active worksheet in workbook open in a session and then populates a variable with the worksheet index.

Copy
<AMEXCEL ACTIVITY="get_worksheet" SESSION="mySession" WORKSHEETINDEXVARIABLE="theIndex" WORKSHEETNAMEVARIABLE="theName" />