Paste error

topi1

Active Member
Joined
Aug 6, 2014
Messages
252
Office Version
  1. 2010
Why do I keep getting pate error when I copy text from non-excel program and then use the keyboard short cut to run the following vba?

VBA Code:
   Range("A1").Select
    ActiveSheet.Paste
    Range("B1").Select
    Selection.Copy
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I'd say because the code did not copy anything so as far as Excel is concerned there is nothing to paste. Look for code that accesses the clipboard. I don't know if I have any but will look. Maybe search on "Excel vba paste from clipboard"
 
Upvote 0
This is all I have that might be of some use to you. It puts the text selected in a userform textbox into the clipboard, then gets it from the clipboard and presents it in a message box. The key parts for you would be the dataobject parts.
VBA Code:
Private Sub CommandButton1_Click()
Dim strclipboard As String
Dim objData As Object

Set objData = New DataObject
strclipboard = Mid(Me.TextBox1, Me.TextBox1.SelStart, Me.TextBox1.SelLength)
objData.SetText strclipboard
objData.PutInClipboard
MsgBox objData.GetText(1)

End Sub
 
Upvote 0
This is all I have that might be of some use to you. It puts the text selected in a userform textbox into the clipboard, then gets it from the clipboard and presents it in a message box. The key parts for you would be the dataobject parts.
VBA Code:
Private Sub CommandButton1_Click()
Dim strclipboard As String
Dim objData As Object

Set objData = New DataObject
strclipboard = Mid(Me.TextBox1, Me.TextBox1.SelStart, Me.TextBox1.SelLength)
objData.SetText strclipboard
objData.PutInClipboard
MsgBox objData.GetText(1)

End Sub
Did not work for me. I don’t understand it.
 
Upvote 0
If you are manually copying something from another application and using the macro to paste it try:
VBA Code:
    Range("A1").PasteSpecial Paste:=xlPasteAll
 
Upvote 0
If you are manually copying something from another application and using the macro to paste it try:
VBA Code:
    Range("A1").PasteSpecial Paste:=xlPasteAll
@Micron and @Alex Blakenburg I tried everything, including codes both of you provided, but nothing was working consistently. Finally, I added a step in the start to activate excel and clear cell A1 contents before doing anything else. Now it works consistently. Thank you both for your help.
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,337
Members
453,032
Latest member
Pauh

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