I have a VBA script that I’m trying to use in Power Automate Desktop, but I’m encountering some error. I would appreciate it if someone could help me identify any potential issues.
Here’s my script:
Dim objFSO, objFile
Dim OrderNumber, MatchedFile
Dim Files
OrderNumber = CStr("%varOrderNumber%")
Files = "%varCardsListInShopFolder%"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each File In Files
Set objFile = objFSO.GetFile(File)
If InStr(objFile.Name, OrderNumber) > 0 Then
MatchedFile = objFile.Name
Exit For
End If
Next
If MatchedFile <> "" Then
Result = MatchedFile
End If
WScript.Echo Result
**
The script is supposed to do the following:
- Set the value of OrderNumber to the value of %varOrderNumber% (it is my variable set in the flow).
- Set the value of Files to the value of %varCardsListInShopFolder%
- Create a FileSystemObject which allows for manipulation of the file system.
- Search through the list of files specified by Files.
- For each file in the list, check if the file name contains the order number specified by OrderNumber.
- If the file name contains the order number, save the file name to MatchedFile and exit the loop.
- At the end, if MatchedFile is not empty, display a message that the matched file was found. Otherwise, display a message that no matched file was found.
I’m replacing %varOrderNumber% and %varCardsListInShopFolder% with actual values or variables available in my script environment before running the script. The varOrderNumber is a number consisting of several digits, and varCardsListInShopFolder is a list of file paths containing full file names with the path (e.g., C:\Users\BP 45\OneDrive - MY\POWER AUTOMATE\xxxxx\yyyy\1517\1517 xxxxx XXXXXXXX_aaaaa Bbbbbbbb_07.06.2024_02.05.10_22708.pdf).
The error I’m getting is: (9, 203) Microsoft VBScript - compilation error: Lack of end of character constant
Any help would be greatly appreciated!