Excel - Activate Worksheet
Declaration
<AMEXCEL ACTIVITY="activate_worksheet" CONNECTBY="text (options)" WORKBOOK="text" INVISIBLE="YES/NO" WORKBOOKTEMPLATE="text" OVERWRITE="YES/NO" SAVETYPE="text (options)" DESTINATION="text" OVERWRITEDESTINATION="YES/NO" BYINDEX="YES"/NO WORKSHEET="number" />
Description: Activates a worksheet in a workbook from an established Excel session.
Practical Usage
Used to activate an existing worksheet inside a Microsoft Excel document that was previously created or opened using Create Workbook or Open Workbook actions. Other Excel actions such as Activate Cell or Get Active Cell can be used in subsequent steps.
Resource Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Resource |
|
|
|
|
Indicates where the source Excel document should originate from. This is a design mode parameter used only during task construction and configuration, thus, comprises no markup. The available options are:
|
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 active only if the Resource parameter is set to Session. |
Get document by |
Text (options) |
Yes if Resource is set to File |
Open |
|
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:
|
File name |
Text |
Yes |
(Empty) |
WORKBOOK="C:\Temp\file.xls" |
If the Get document by parameter is set to Open, specifies the path and filename of the Excel document in which to open. If the Get document by parameter is set to Create, specifies the path and filename of the Excel document in which to create. |
Application is invisible |
Yes/No |
No |
No |
VISIBLE="NO" |
If set to YES, specifies that the Excel window will not be displayed and all processing will occur in the background. This option should be set to NO during task construction and debugging but can be set to YES 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 enabled, specifies the path and filename 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 active only if the Get document by parameter is set to Create. It is disabled by default. |
Overwrite if workbook already exists |
Yes/No |
No |
No |
OVERWRITE="yes" |
If set to YES, the newly created workbook will overwrite an existing workbook with the same name, If set to NO, an error will occur during runtime as a result of a matching filename. This parameter is active only if the Get document by parameter is set to Create. |
On completion |
Text (options) |
No |
Save |
|
Specifies what to do with the document upon completion of this activity. The available options are:
|
Overwrite if workbook already exists |
Yes/No |
No |
No |
OVERWRITEDESTINATION="YES" |
If set to YES, specifies that existing Excel files with matching names that exist in the destination will be overwritten. If set to NO, matching files will not be overwritten, however, a runtime error will occur as a result. Set to NO by default. |
Worksheet Parameters
Property |
Type |
Required |
Default |
Markup |
Description |
---|---|---|---|---|---|
Activate worksheet by name |
Text |
No |
(Empty) |
WORKSHEET="Sheet1" |
If enabled, specifies the name of the worksheet to activate. |
Activate worksheet by index |
Yes/No |
No |
No |
BYINDEX="YES" |
If set to YES, specifies that the worksheet will be activated by index number. |
Index |
Text |
Yes |
1 |
INDEX="2" |
The index number to activate. This parameter is active only if the Activate worksheet by index parameter is set to YES. |
Description tab - A custom description can be provided on the Description tab to convey additional information or share special notes about a task step.
Error Causes tab - Specify how this step should behave upon the occurrence of an error. (Refer to Task Builder > Error Causes Tab for details.)
On Error tab - Specify what AWE should do if this step encounters an error as defined on the Error Causes tab. (Refer to Task Builder > On Error Tab for details.)
Example
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. Each each step of the task is described below, including the action used and details about that action.
-
Create Workbook Action - Create new Excel workbook "C:\Temp\sampledoc.xls". Overwrite file if it already exists.
-
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.
-
Activate Worksheet Action - Activate Excel worksheet "My New Sheet" in workbook open in session "ExcelSess1".
-
Set Cell Action - Write text "Set this data here" in Excel cell located at row:1 and column:1.
-
Pause Action - Pause task for 3 seconds.
-
Set Cell Action - Write text "and this here" in Excel cell located at row:2 and column:1.
-
Pause Action - Pause task for 3 seconds.
-
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" />