UIPath Type Into Excel using alt for formatting issue

I am building one of my first bots and am currently having an issue with Type Into and selectors that I cannot figure out.

The main task of this bot is to automate some Excel formatting, applying the same formatting to (the only) two sheets in an Excel workbook. I am using “Type Into” block with “[k(alt)]” followed by the appropriate keystrokes to set the formatting I want. However, I am having an issue where sometimes the “alt” keystroke doesn’t get sent and the following keystrokes end up getting typed into a cell. I have tried many different selectors as well as checking and unchecking different options on the type into and separating the alt keystroke from the following letters (using two type into’s, one for the alt and one for the keystrokes) and am not able to get both the first sheet and the second sheet to both be formatted. Either the first sheet never gets the first alt keystroke and the whole workflow doesn’t run or the first sheet gets formatted but the second sheet never gets the second alt keystroke sent.

I have a formatting chain (written in a “Do” block) and am looping through using “for each sheet in wb.GetSheets” and when I run the workflow, it correctly formats the first sheet but then when it switches to the next sheet it does not send the “alt” stroke even though it is in the “Do” block and the letters instead get typed into a cell. If anyone had any guidance on this (correct selectors, type into options, approach other than “for each…”) I would greatly appreciate it.



Here was my reply to you in DM, for those having issues with this as well.

The selector I used was the element where the spreadsheet is contained, but I use a dynamic selector, like this:
"<wnd app='excel.exe' cls='XLMAIN' title='*"+System.IO.Path.GetFileNameWithoutExtension(filepathOut)+"*' /><wnd cls='EXCEL7' title='*"+System.IO.Path.GetFileNameWithoutExtension(filepathOut)+"*' /><ctrl name='*"+System.IO.Path.GetFileNameWithoutExtension(filepathOut)+"*' role='client' />"

where filepathOut represents the filepath being opened in Excel. - and you normally don’t want to include the extension or window title in the title attribute, since that can change environment to environment.

Here is a snippet from a working flow:

I think the key is to use “ralt” or “lalt”; the regular “alt” has glitches and will get locked up or fail to type.

So ideally, you want to use a Select Range, then your Type Into.
For a dynamic range, you will need to assign the column using a modulo calculation, like shown in this image:

Inside the Do while shown in image, here are the calcuations:

colModulo = (colDividend-1) Mod 26
colName = Convert.ToChar(65 + colModulo).ToString + colName
colDividend = CInt((colDividend - colModulo) / 26)

I initialized colDividend based on the column being looked at:

where col represents a DataColumn like inside a ForEach col In dt1.Columns
or a hardcoded column like dt1.Columns(0)

That should calculate the columnname from A to ZZ (or whatever is last column)

Additionally, you might also consider looking at vbscript. You can use that inside the Invoke VBA activity. I have used this a few times and seemed pretty easy. Essentially, you can use an Excel Scope, then place the Invoke VBA to perform an action inside the scope on the file. - this vbscript would be in a text file with extension .vbs … Anyway, vbscript is smoother, if that’s something you are interested in.

I have this very powerful Update Excel shared workflow component, which I’m now using in all projects to append new transaction items to the end user log file, and it will format if desired based on certain arguments. However, to be honest, if I had the time, I would probably reorganize that component to do all its updating in vbscript.

Regards, sir


The key piece for me was using lalt/ralt in place of regular alt. Thanks for the help!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.