How to get the full path of Microsoft Excel into a variable

Hello all,

I am having an issue with trying to get the full path of the Excel, On my machine, it is installed on a different location than the VM that it is supposed to run and I tried assigning it to a variable with

“new FileInfo(“EXCEL.exe”).FullName,” but it’s returning as a directory the project folder in which I’m working. Is there any way to get it dynamically?

Much apreciated.
Cheers!

Hey @goncalo.rocha ,

Try using the below code

Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "", "")

image

Hope it helps you!

1 Like

FYI this is trying to get the fileinfo for a file named EXCEL.exe in the current folder. It doesn’t function as a search for that file.

Hello, this has to be use on cmd?
if so, how can I then transform the output into a variable?
Thank you for all the help.

Hi @goncalo.rocha

To dynamically obtain the full path of the Excel executable (EXCEL.EXE) on the machine where your automation is running, you can use the Windows Registry. The Excel executable path is usually stored in the Windows Registry. Here’s how you can do it in UiPath:

  1. Use the “Invoke Code” activity to execute a short snippet of VB.NET code to retrieve the Excel executable path from the Registry.

  2. Here’s a sample code snippet you can use:

Dim excelPath As String = Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "", "").ToString()

If Not String.IsNullOrEmpty(excelPath) Then
    ' The 'excelPath' variable now contains the full path to the Excel executable.
    ' You can use it in your workflow.
    LogMessage("Excel Path: " & excelPath)
Else
    LogMessage("Excel not found or registry key not present.")
End If

This code retrieves the path to the Excel executable from the Windows Registry, specifically from the “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe” registry key.

  1. Make sure to replace the LogMessage activity with your desired actions, such as assigning the Excel executable path to a variable.

  2. Run your workflow, and it will dynamically obtain the path to the Excel executable on the machine where the automation is running.

Please note that this method relies on the registry key mentioned, and it may require administrative privileges to access the Windows Registry. Additionally, the registry key may vary slightly depending on the version of Windows you are using, so make sure to test it on your specific environment.

Thanks!!

1 Like

Hey @goncalo.rocha ,

You can use a Assign activity

left side would be a string variable
right side would be the code

Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe", "", "").ToString

Refer below screenshot

So now excelPath will have the path of EXCEL.EXE
You can use that variable in your code

Hope it helps you !

Worked perfectly thank you very much,
and thank you to everyone that tried to help aswell.

1 Like

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