Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using SendKeys in VBS - Copy/Paste

Using SendKeys in VBS - Copy/Paste

Using SendKeys in VBS - Copy/Paste

What am I doing wrong?

I can copy and paste my relevant data into notepad, word, and even point of sale software but I cannot seem to get my vbs script to paste into it's own input box.

I am very confuzzled.

First part copies item number to be pasted into script:

WshShell.AppActivate "Touchscreen Ticket Entry"
WshShell.SendKeys ("%a")
WshShell.SendKeys ("^C")

Safety Pause for copy to take hold:

wsh.sleep 1000

This part creates input box to paste into:

Itemno = InputBox("Enter Item Number:", "Item Number")
WshShell.AppActivate "Item Number"
WshShell.SendKeys "^V"

If I replace input box with notepad it pastes in even without the safety pause.
I have tried ("^V"), ("{^V}"), ("^{V}"), {paste} and many other ways to get this to paste into itself and have plum run our of ideas.

Please help advise me to my error or what I am missing if you can. I am just starting to thing vbs just wont paste to itself

And I can to a physical keyboard ctrl-v from the keyboard and it pastes just fine

RE: Using SendKeys in VBS - Copy/Paste

Ctrl+C, Ctrl+V should work too.
But you have to get rid of your parentheses:


WshShell.SendKeys ("%a")
WshShell.SendKeys ("^C") 


WshShell.SendKeys "%a"
WshShell.SendKeys "^c" 

Parentheses only if the expression is on the rigt hand side of an equal sign.

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Using SendKeys in VBS - Copy/Paste

It was tried with and without the parenthesis. No worky

But I did find a way to do it which took more programming knowledge than I started with.

For some reason the sendkey commands didnt like pasting to itself so I set up an array and an outside file to save the data then read it back in.

I know, I know... Round about way. But I got-r-done and the client loves it


RE: Using SendKeys in VBS - Copy/Paste

A little bit cleaner solution for you, you coudl use this after copying your text to the clipboard with Ctrl+C:

CODE --> VBScript

Set objHTML = CreateObject("htmlfile")
ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text")
Itemno = InputBox("Enter Item Number:", "Item Number",ClipboardText)
Set objHTML = Nothing 

I hope that helps.



No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close