Send path from UIPath to macro

I have variable path(string) = “C:\Users\Titi\Desktop\input\ “+month+”_”+year+".xlsx"

I want to send path to macro for open file instead of in path square red as below.

Please guide me.

Hi @fairymemay

Please refresh to the below post

@prasath_S Year and month are not pass to macro as below.

My variable as below.
month = Date.Now.AddDays(-3).ToString(“MMMM”)
year = Date.Now.AddDays(-3).ToString(“yyyy”)

Maybe something wrong with path.

You can try to first assign a variable = month + “_” + year + “.xlsx” as let’s say “ExcelPath”

Then pass it into the path.

Kah Liang

@fairymemay first check if the file is present using path exists activity.

Or first send the file path as hard-coded and not on the variable

send the file path as hard-coded // work completed not error.

@Kah_Liang Same error.
month and year not send value to macro.

From your screenshot it looks like the variables month and year are empty. Have you checked that the path variable looks correct before sending it to the macro? (You can use Write Line to print the variable value to the Output panel to check.)

@ptrobot It show value correct.

Thanks! And how does path look?

could you please put path variable in the message box and send what the path looks like

@ptrobot @prasath_S message box path not show month and year.

@fairymemay show the syntax where you are appending both the path ,month and year.

When do you assign the month and year? It should be before the path assignment.

month = Date.Now.AddDays(-3).ToString(“MMMM”)
year = Date.Now.AddDays(-3).ToString(“yyyy”)
path = "C:\Users\Titi\Desktop\input\"+month+"_"+year+".xlsx"

Or could you share your workflow so we can help you troubleshoot?

1 Like


Your code should be like below

Sub B**(filePath As String)**

Apllication.WindowState = xNormal
Workbook.Open Filename = filePath

End Sub

You missed passing the parameter to your method… Also, create the same variable name(filePath) of type string in the studio from where you are passing the path to execute macro activity…

1 Like

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