SendKey Question

Photomofo

Board Regular
Joined
Aug 20, 2012
Messages
240
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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Photomofo

Board Regular
Joined
Aug 20, 2012
Messages
240
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,279
Messages
5,635,283
Members
416,850
Latest member
Sidddharth

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
Top