Invoke VBA function

Hi,

i need to invoke the function to excel.
The code:
Function GetURL(pWorkRng As Range) As String
GetURL = pWorkRng.Hyperlinks(1).Address
End Function

How do I run this code in excel? I used excel app scope and invoke vba:
image

but I get this error:
image

Hi @markosc

Write the code as macro in excel and use Execute Macro activity to execute that code

Regards
Sudharsan

HI @markosc

Have look on the video link

Here is the sample XAML file

https://docs.uipath.com/activities/docs/invoke-vba

Regards
Gokul

Does anyone know how to insert module to excel?

Hi @markosc

  • Just Go the Developer Tab in the excel
  • Click on the Visual Basic
  • Right click on the Microsoft Excel objects → Insert → Model

Regards
Gokul

I mean through uipath. How do I insert module:
Function GetURL(pWorkRng As Range) As String
GetURL = pWorkRng.Hyperlinks(1).Address
End Function

@markosc you cannot insert a module in excel through UiPath

  • You can use VB code directly to perform any actions within the excel without creating any modules. Bot will read the code logic from text file
  • Other option is use macros where you can insert module and run the code . To run the macros UiPath has an activity called Execute macro. Use below link for more details

Do you know how do I create new function throug invoke vba? Like this one:
Function GetURL(pWorkRng As Range) As String
GetURL = pWorkRng.Hyperlinks(1).Address
End Function

I need to extract URL from cells that are like this with no url but when I hover over the text it shows url:
image

  1. first change Data\macro.txt to this!
Function GetURL(cellAddress as string) As String
GetURL = Range(cellAddress).Hyperlinks(1).Address
End Function
  1. in your invoke VBA activity, pass in the cell where you want to read the hyperlink

  2. assign output to an object variable e.g. “output”

  3. print output using output.tostring
    image

My example:
Excel:
image
workflow:


Result:
image
TestGetLink.xaml (6.4 KB)
test.xlsx (8.8 KB)

2 Likes
1 Like

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