.sendkeys variable in VBS

July 6, 2009 at 08:58:01
Specs: Windows Vista
I am working on a small VBS script that is *supposed* to enter a user defined variable into excel. What happens istead is that it opens excel and then says there is a problem. When I did not put a variable in, it typed the word in. I need to no how to make the shellobj.sendkeys command work with variables. Here is my code:

DIM userInput
set shellobj = CreateObject("WScript.Shell")
name = inputbox("Please Enter Your Name")
shellobj.run "cmd"
wscript.sleep 500
shellobj.sendkeys "start excel.exe{enter}exit{enter}"
wscript.sleep 3000
shellobj.sendkeys "{& name &}{enter}"

the error message that pops up says
Line: 8
Char: 1
Error: invalid procedure call or argument.

But when I change the shellobj.senkeys "{& name &}{enter}" to shellobj.senkeys "john{enter}" , it works. Please help.

See More: .sendkeys variable in VBS

Report •

July 7, 2009 at 20:23:14
To quote the documentation, "To send brace characters, send the string argument '{{}' for the left brace and '{}}' for the right one."

Report •

July 8, 2009 at 08:06:35
Thanks, that was just what I needed! I am also curious how you send the + symbol using .sendkeys command.

shellobj.sendkeys " + "

This script I am using doesn't work.

Report •

Related Solutions

Ask Question