Solved

Using SendKeys to send Ctrl_c

Posted on 2007-03-17
5
438 Views
Last Modified: 2010-04-30
Why in the world doesn't this work

    Clipboard.Clear
    SendKeys "^c", True ' Ctrl_c ???
    MsgBox Clipboard.GetText
0
Comment
Question by:Martin Liss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 18742455
How are you firing that code?

If, for instance, you fired it in a button click:

    Private Sub Command1_Click()
        Clipboard.Clear
        SendKeys "^c", True ' Ctrl_c ???
        MsgBox Clipboard.GetText
    End Sub

Then the BUTTON would have focus last and there would be nothing to copy...therefore returning a blank string.

If you set focus onto something else first though, like a TextBox...then you get very different results:

    Private Sub Command1_Click()
        Text1.SetFocus
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)
        Clipboard.Clear
        SendKeys "^c", True ' Ctrl_c ???
        MsgBox Clipboard.GetText
    End Sub
0
 
LVL 48

Author Comment

by:Martin Liss
ID: 18742565
Thanks.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question