1. Pass Variable via Command-Line Arguments (Recommended)
Use Case:
You trigger Power Automate Desktop flow from VBA and pass your variable (e.g., CustomerID, Amount, FilePath) as a command-line argument.
How To Do It:
Step 1: In PAD
Open your PAD flow.
At the top, click on "Input/Output variables"
Create a new Input variable (e.g., MyInputVar)
Set its type as Text
Step 2: Use CMD to Run PAD Flow with Variable
You can trigger PAD from VBA using Shell like this:
Sub RunPADFlowWithVariable()
Dim variableValue As String
variableValue = "HelloFromExcel"
Shell "C:\Program Files (x86)\Power Automate Desktop\PAD.Console.Host.exe -f ""MyPADFlowName"" -i ""MyInputVar=" & variableValue & """", vbNormalFocus
End Sub
This runs your PAD flow and sets MyInputVar to "HelloFromExcel"
2. Use a Temporary Text File
If the data is complex (like arrays or multiline text), use a shared file.
VBA writes value to file:
Sub WriteToTempFile()
Dim filePath As String
filePath = "C:\Temp\input.txt"
Open filePath For Output As #1
Print #1, "ValueFromExcel"
Close #1
End Sub
PAD reads file:
Use "Read text from file" in PAD to capture the value.
3. Use Excel File as the Data Source
If you're already in Excel, let Power Automate Desktop:
Open the file
Read the cell value using "Read from Excel worksheet"
This is slower but requires no variable passing from VBA.
If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
Regards,
Riyaz