trying Sendkeys in VBA for copy paste but not working

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,584
Office Version
  1. 365
Platform
  1. Windows
I am trying to copy and paste using Sendkeys but it doesn't work.

VBA Code:
Sub trial()
Application.SendKeys "^C", True  'Pressing Ctrl + C to copy activecell

Application.SendKeys "%{Tab}", True 'Pressing alt tab to go to another excel 

Application.SendKeys "^V", True   ''Pressing Ctrl + V to paste in the Userform's textbox which is opened

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I'm not sure why you'd want to use SendKeys. It's also not clear to me what you're trying to do, but perhaps it's something like this?
VBA Code:
Sub SelectionToTextBox()
    TextBox1 = Selection.Value
End Sub
Where Sheet1 has the code and the TextBox you can see in the Worksheet is TextBox1.
1587802015347.png
 
Upvote 0
Thanks kennypete, for the response.

However, the excel in which the UserForm is situated is locked in such a way that the moment the UserForm gets loaded, all the instances of Excel gets locked. You can't even click on anything except the UserForm.

Anyway, I am no longer working for that project. So it's fortunate for me.
Have a great day!!
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,146
Members
448,948
Latest member
spamiki

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