Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using SendKeys in VBS - Copy/Paste

Status
Not open for further replies.

chaznbs

IS-IT--Management
Jun 5, 2015
23
US
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
 
Ctrl+C, Ctrl+V should work too.
But you have to get rid of your parentheses:
Wrong:
Code:
WshShell.SendKeys ("%a")
WshShell.SendKeys ("^C")
Correct:
Code:
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.
 
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


CLOSED
 
A little bit cleaner solution for you, you coudl use this after copying your text to the clipboard with Ctrl+C:
Code:
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.

Regards,

Mark

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

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top