Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a way to "trap" paste operations in Excel

Status
Not open for further replies.

chuckschilling

Programmer
Aug 7, 2003
5
US
Hi! I've got a problem that's got me stumped. I was hoping to figure out a way to "trap" the event as a user pastes into an Excel worksheet. I'd like to be able to gracefully reverse the paste and present the user with an informative dialog box. Alternatively, I can live with a solution that disables pasting altogether, but the worksheet absolutely must retain its current autofill properties as this is a requirement of the project.

Any ideas?
 
Hi,

Don't think that you can detect a paste event. Closest that you might come is to use the Worksheet_Change event when Target.Cells.Count > 1.

Certainly in THAT case, a paste event occured.

However, it is impossible to discriminate between a single cell change caused by a paste or [ENTER].



Skip,
Skip@TheOfficeExperts.com
 
a good starting point is to have

application.cutcopymode = false

in the SELECTION change event

ie if they copy and then move to a new cell, the clipboard gets emptied. this stops the paste but doesn't give the user a reason

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Hi Chuck,

The following code will clear the office clipboard completely. Unfortunately, it won't work in XP though due to the new clipboard format.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.CutCopyMode = False
On Error Resume Next
Application.CommandBars(98).Controls(4).Execute
On Error GoTo 0
End Sub
[/color]

I hope this helps!




Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top