SendKey Question

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
I've never used SendKey instructions before. I know they're considered a last resort but it's either SendKey or Macro Express and I haven't been particularly happy with Macro Express.

My goal here is to click on a window , select all, copy and paste the data into a spreadsheet. I'm currently selecting a worksheet in excel but ultimately I'm going to be copying data from a separate application.

I can see that I'm getting the CLICK and the CNTL + A to select all but the COPY and PASTE instructions don't appear to be going through.

Any advice?

VBA Code:
Sub ABC()

Sheets("Results").Select
SetCursorPos 300, 400 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.SendKeys "^a", True
Application.Wait (Now + TimeValue("0:00:03"))
Application.SendKeys "^c", True
Application.Wait (Now + TimeValue("0:00:03"))
Sheets("Test").Select
Sheets("Test").Range("A1").Select
Application.SendKeys "^v", True

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I'm noticing some strange behavior with this macro. Basically I'm showing that the CONTROL + A instruction is being seen as a send the letter a instruction but it's ending up on the "Test" page rather than the results page.
 
Upvote 0

Forum statistics

Threads
1,215,346
Messages
6,124,417
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top