Assign Value to Office

Assigns a value to an existing location in an Office file.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

officeSet --location(String) --value(String) --officeapplication(OfficeApplication)

Dependencies

  • To use this command, open an Office file with the Open Office file (officeOpen) command.
  • Microsoft™ Office 2010 or higher is required.
  • Ensure that the architecture (bitness) of your Office apps, IBM RPA, and your operating system match. For example, if you are using a 64-bit operating system, IBM RPA and Office must be 64-bit too.

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Location location Required Text Location of the Office file to assign a value to. See the location parameter for more details.
Value value Required Text, Number, Boolean, Date Time, Date, Data Table Value to be assigned to the file at the specified Location.
Office Application officeapplication Required Office Application Variable that stores the Office Application instance.

location parameter

The location parameter accepts a string that specifies the location to assign value to. The format of this string varies depending on the type of Office file that you are working with.

  • Word files

Enter the page number that you want to assign a value to. For example, if you want to assign a value to the page 1 of the Word file, type in: 1.

Important: The command replaces everything on the page with the value that is assigned to the value parameter.

  • PowerPoint files

Enter the slide number followed by a semicolon, then the object index that you want to assign value to. For example, if you want to assign a value to the object 2 on slide 1, type in: 1;2. The command searches following the index order of objects contained in the slide.

You can also do: slideNumber;objectType[objectIndex], for example: 1;Textbox[1]. All index values start at 1.

Important: The command replaces everything on the object with the value that is assigned to the value parameter.

  • Excel files

Enter the name of the sheet followed by a space, then the cell reference that you want to assign a value to. For example, if you want to assign a value to cell C5 in a sheet called "stockTable", type in: stockTable C5.

Example

The following code example demonstrates how to assign a value to an excel file. The Open Office File (officeOpen) command opens an Excel file, and the Assign Value to Office command assigns the value "Phone" to the cell C1 in the sheet called "sheet1".

defVar --name assignedValue --type String --value Telefone
defVar --name officeApplication --type OfficeApplication
// Download the following file to run the command.
officeOpen --path "Sample file" --type "Excel" --keepvisibleofficeApplication=officeapplication
officeSet --location "sheet1 C1" --value ${assignedValue} --officeapplication ${officeApplication}
officeSave --fileformat "Default" --officeapplication ${officeApplication}
logMessage --message "${assignedValue}" --type "Info"
officeClose --officeapplication ${officeApplication}