Type into: Indicate in Excel failed. Cannot attach to document

Hello community,
I am working within the ExcelProcessScope and trying to use type into activity to enter some values into the excel sheet. However, I am getting the error below:

image

image

This error occured with other activities like Click activity as well. I am getting this error with or without opening the excel file. Can anyone please help with a solution to this error?
Many thanks!

Hey,
The file on which you are working it should close while executing the code
Thanks

@Rounak_Kumar1, I get this error even when the file is closed.

Hello @Emmy_O

Why you are going for the Ui based automation in the excel instead of using the excel package?

Thanks

Don’t use Type Into. Use the Excel activities like Write Range, Write Cell, Append Range, etc.

Have you done the free training on UiPath’s web site? It covers things like this.

Hello @Emmy_O

For excel automation there a package available UiPath.Excel.Activities

From this package you can use write cell activity to enter some values in the excel. But doing UI Automation for excel is not recommended. Hope this helps!

Hey!

Could you please explain the process… what you’re trying to achieve?

We can’t use the excel like this…

Could you please go through some courses available in academy…

Follow the links below

  1. RPA Developer Foundation (v2020.10)

  2. RPA Developer Continuous Learning

  3. RPA Developer Advanced (v2020.10)

Regards,
NaNi

1 Like

Hi @Rahul_Unnikrishnan, @Rounak_Kumar1, @THIRU_NANI and @postwick, many thanks for your responses.
Sorry for the confusion that was generated by my question. What I wanted to achieve is to send keys to the Excel sheet and not actually to type in some values. Here is a simple breakdown of my workflow:

  1. Fetching unstructured text from a website with the Get Text activity
  2. Save the text in a datatable with Generate Data Table activity
  3. Get the last row with text from my excel sheet
  4. Then append this text into an Excel sheet (range LastRow + 1) with the Write Range activity.
    This simple workflow works pretty fine. But after testing with lots of input data, there were cases where the text data have duplicate values. So, while saving into the datatable, it would throw an error that the table could not be created because of duplicate column names.

My approach at resolving this therefore is to save the text to clipboard and then try to paste it into the excel sheet with a send hotkey activity. So, I am doing the following:

  1. Use the Select Range activity to the cell I want to paste into
  2. Use send hotkey activity (classic activity without any selector) to send Ctrl + v to paste the text into the selected cell.
    But unfortunately, this does not work. I also used Type into activity (Classic) to send “[K(Alt)]”+“h”+“v”+“t” into the excel sheet, and this also did not work. This then led me to using the Type into activity (modern design) and generated the error that I posted in the question. But it is good to know now that UI based automation does not work in Excel.

My other aproach has been to use a VBA script and then pass the range variable as a parameter within the function. This is also not working right now. But I guess I need to look more into the function.

In addition to pasting the text into Excel, I also need to use send keys to send keyboard shortcuts (Alt + H + B + A) to create thick borders around every table in the sheet for readability.
So, my question then is what is the best way to send keys to an Excel sheet if UI based automation is not recommended in Excel?

Hello @Emmy_O

You can use Write range or Append range activities to write your data. Or if you want to specifically write to a cell, then use Write Cell activity.

Thanks

Write range and Write Cell activities are writing the whole chunk of text into a single cell. For my use case, the text could sometimes be up to 40 rows. Therefore, I need to use a keyboard shortcut to preserve the formatting of the text.

you can do one thing first you can use write text file to write in notepad and Read from Notepad then you can write in Excel by write range Activity

Thanks,
Rounak

Thank you @Rounak_Kumar1 for this nice suggestion. I thought about this before but I was afraid of the impact on the runtime. I think I will give it a try now. Many thanks.

Hi @Rounak_Kumar1,
Unfortunately, this approach does not also work :slightly_smiling_face: The text is still being pasted into a single cell.
My workaround solution now is to add a special character to the line that was always creating duplicates in my text data. That way, I can use Generate Data Table activity without any conflict of duplicate column. Then, I am using a Find/Replace activity to remove the special character afterward before saving the output sheet.
However, I still need to know the best approach to send keys in the Excel activity. For example, I need to send keyboard shortcuts (Alt + H + B + A) to create borders around every table in the sheet for readability because I could sometimes have more than 20 different tables in the sheet.

hey,
you can do like that
step 1- Move the text file and change the name from “file.txt” to “file.csv” .
step 2- Read the CSV with delimiter of “TAB” .
step 3-Write the excel back to the .xlsx file(Or any format).
Thanks

I got the same error. It’s actually one of the video on UiPath Academy. The instructor use the Click activity inside Use Excel File.

Hello @minhle

Welcome to UiPath community!

Open the excel file and start indicating on it. The above issue might occur when you trying to indicate the excel without opening

Hi @minhle,
I solved my problem by using the classic activities. I tried everything with the Modern design activities and I was not able to select the UI element even with the Excel file already opened.
image
Just ensure that show classic is checked in the Activities tab, and then, you should see the classic activities.