PastSpecial problem

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have this code that seemed to be working in the past, but now the users are getting an error message. if they are copying from another Excel workbook it works but if they are copying from any other source (like Notepad) they get an error

Run-Time error '1004':
PasteSpecial Method of Range class failed.

Code:
Sub PastePropVersion()
'PasteButton


Sheets("ProPricer Info").Range("D12").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False


End Sub

Thanks for the help
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Since you are pasting values only, you could skip using PasteSpecial, retrieve the text from the clipboard using the DataObject and assign the retrieved clipboard text directly to cell D12
VBA Code:
Sub PastePropVersion()
    'PasteButton
    Sheets("ProPricer Info").Range("D12").Select
    With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .GetFromClipboard
        If .GetFormat(1&) Then
            Selection = .GetText(1&)
        Else
            MsgBox "Clipboard Empty!"
        End If
    End With
    Application.CutCopyMode = False
End Sub
 
Last edited:
Upvote 1
Solution
A direct assignment should work. The reason PasteSpecial does not work for data copied from external sources is that PasteSpecial requires an Excel range.
 
Upvote 0
Since you are pasting values only, you could skip using PasteSpecial, retrieve the text from the clipboard using the DataObject and assign the retrieved clipboard text directly to cell D12
VBA Code:
Sub PastePropVersion()
    'PasteButton
    Sheets("ProPricer Info").Range("D12").Select
    With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .GetFromClipboard
        If .GetFormat(1&) Then
            Selection = .GetText(1&)
        Else
            MsgBox "Clipboard Empty!"
        End If
    End With
    Application.CutCopyMode = False
End Sub
Thank you
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,096
Latest member
Anshu121

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