'method run object iwshshell3 failed vba
I am trying to automate file upload on chrome, getting error here :method run object iwshshell3 failed" please help:
Dim Customer_rates As String
Dim WshShell As Object
Customer_rates = "D:\FX Exch. Rates\2022-Feb-24 1707\MP_customer_exchange_rates_sample.xlsx"
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd.exe/c echo" & Customer_rates & "| clip", vbNormal, True
WshShell.SendKeys "^{v}"
Application.Wait DateAdd("S", 2, Now)
WshShell.SendKeys "{ENTER}"
Solution 1:[1]
Think about how this would appear in the console. The file path has spaces. So it will require quotes around it when you run it. Something like:
WshShell.Run "cmd.exe/c echo" & chr(34) & Customer_rates & chr(34) & "| clip", vbNormal, True
Solution 2:[2]
Thansk guys i did a workaround of cmd with this sub and it semms to work:
Sub StoreData() Dim varText As String Dim objCP As Object varText = "D:\FX Exch. Rates\2022-Feb-24 1707\MP_customer_exchange_rates_sample.xlsx" Set objCP = CreateObject("HtmlFile") objCP.ParentWindow.ClipboardData.SetData "text", varText End Sub
Solution 3:[3]
Try to always work with absolute paths (program and arguments). Be aware of quotes. I preferably use chr(13)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sivakanesh |
Solution 2 | Stoyan Bozhkov |
Solution 3 | Athena |