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?
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:
Use the “Invoke Code” activity to execute a short snippet of VB.NET code to retrieve the Excel executable path from the Registry.
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.
Make sure to replace the LogMessage activity with your desired actions, such as assigning the Excel executable path to a variable.
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.