Solved

Using SendKeys to send Ctrl_c

Posted on 2007-03-17
5
419 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
5 Comments
 
LVL 85

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 45

Author Comment

by:Martin Liss
ID: 18742565
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now