I am trying to automate file upload on chrome with this VBA:
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}"
I get this error:
method run object iwshshell3 failed
.SendKeys()
CTRL+V, when you could.SendKeys()
the actual filename?+
,[
,]
,^
,%
,~
,{
,}
,(
,)
as{+}
,{[}
,{]}
,{^}
,{%}
,{~}
,{{}
,{}}
,{(}
,{)}
, respectively - but other than that you can send the filename directly withSendKeys
and skip the clipboard entirely. You could make a small helper function e.g.Function MakeSafeForSendKeys(string)
that does these replacements and returns a safe value. Then you can callWshShell.SendKeys MakeSafeForSendKeys(Customer_rates)
and it should work.