Multiple Copy-Paste To-From ClipBoard Not Working

R

Red Rider

I’m trying to copy data from MYAPP into the clipboard, display the
data, then copy other data into the clipboard and display that data.
When I switch to MYAPP the text in Line 1 is automatically highlighted
so the SendKeys “^c” works OK and the 1st MsgBox displays “Line 1
Text” but when it moves to Line 2 (I verified it does move to Line 2
and is highlighted) and does another copy (SendKeys “^c”) it displays
“Line 1 Text” again, not “Line 2 Text.” I’ve tried clearing the
clipboard at the start, in the middle and at the end of the program
but I can never display both lines of data. It’s either one or the
other but never both. Is it possible to do multiple copy – paste
functions within one program? Any help would be appreciated.

Sub TestMultipleCopiesToClipboard()

Dim x As New DataObject, WshShell As Object

Set WshShell = CreateObject("WScript.Shell")

WshShell.AppActivate "MYAPP"

' go to Line 1 containing "Line 1 Text"
SendKeys "^c"
x.GetFromClipboard
WshShell.AppActivate "Microsoft Excel"
MsgBox x.GetText

WshShell.AppActivate "MYAPP"
‘ Tab to Line 2
SendKeys "{TAB}" & "{TAB}" & "{TAB}"

' go to TextBox2 containing "Line 2 Text"
SendKeys "^c"
x.GetFromClipboard
WshShell.AppActivate "Microsoft Excel"
MsgBox x.GetText

' Clear ClipBoard
‘ This works fine but doesn’t help to display both lines above, no
matter where it’s placed
' x.SetText ""
' x.PutInClipboard

End Sub
 
R

Red Rider

It looks like if I put "True" at the end of both SendKeys this program
will run correctly. Maybe this will help someone else out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top