How to get the handler when i create the instance of excel?

excel
activities

#1

hi everyone,

I have a question, for example i need get the instance when i invoke the excel,
How do I get the number of the instance?

thank you


#2

Hi @elvbis,

Are you looking for something like this.

Main.xaml (7.7 KB)

Here, in the output log, you can see each and every Process and its Process ID.

Then u can look only for Excel one and get ts Process ID .

Please correct me if I have misunderstood your question .


#3

Hi Elvbis,

If you have the selector for the Excel, you can use the following code in the Write Line activity in order to get all the possible attributes and values for the element:

string.Join(",",new UiElement(new Selector("<wnd app='iexplore.exe' cls='#32770' title='Message from webpage' />")).GetNodeAttributes().Select(function(o) o.Key & ": " & o.Value))

#4

multiple answers to mystery question

Process.GetProcessesByName(“EXCEL”).Length.ToString


#5

@vvaidya,

I am not sure sure bro whats he exactly looking for.

Number of that instance - is it the Process ID , Session ID , or some number that I am unaware of ?


#6

Hello,

Do you mean the “handle” aka HWND? (<> than process id).
HWND apply at different levels.

-The Excel process level
-The Excel window level

Note that an Excel process can hold different windows inside itself, it is generally the case when they are open manually.

on the other hand, when (most of the time…) excel windows are open programmatically (or using excel.exe \x) the new excel application (held inside the window) contained inside a new excel process, parent of the created windows.

If what you refer as the instance is this parent process, you can access it by using
Process.GetProcessesByName(“EXCEL”) loop inside them and access to the .handle property from process object.

However, if by the instance you refer to to window itself then, from the parent process object you can access using processobject.mainwindowhandle. Be carefull however, if you excel parent process hold more than one application, it will only access the one (the application or window) which is foreground. when you will use it. You can easyly observe this behavior using the UiExplorer too.

Finally, meanwhile is technically possible to access the handles of the excel window coming from interop in a much easier way in .Net or even VBA. by using for example workbookObject.HWND, UiPath is using the lattest version of interop which is exposing much less methods than older ones. “Option strict On” prevent you to do that with UiPath as per my experience so far.

So overall no bulletproof of silverbullet solution but some tought about it from my side…

Hope it somehow help you

Cheers


#7

thank you