Using UndoAction to undo a paste

E

Evi

I have Word 97

I wanted to stop users pasting into a user form's text box using Ctrl + V
but I want them to be able to type into it.

I thought that I could use the Textbox BeforeDropOrPaste event. I thought I
could put
Userform1.UndoAction
into the BeforeDropOrPaste event of the text box but when I try this I get
the
'Unexpected Call to Method or Property Access'

There aren't any examples in the Help for BeforeDropOrPaste so I'm not sure
how to make it work.

Could the settings for Shift be used somehow since the user would have to
use Ctrl + V to paste into the text box?

Evi
 
L

Lars-Eric Gisslén

Evi,

Try this:
Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As .......
Cancel = True
End Sub

Regards,
Lars-Eric
 
D

Doug Robbins - Word MVP

Hi Evi,

You can use:

Option Explicit
Dim Pasted As Boolean

Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As
MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As
MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As
MSForms.ReturnEffect, ByVal Shift As Integer)
MsgBox "Pasting into this textbox is not allowed"
Pasted = True
End Sub

Private Sub TextBox1_Change()
If Pasted = True Then
TextBox1.Text = ""
Pasted = False
End If
End Sub

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
E

Evi

Yeah! It works! Thanks Lars-Eric.
Evi

Lars-Eric Gisslén said:
Evi,

Try this:
Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As .......
Cancel = True
End Sub

Regards,
Lars-Eric

thought
 
E

Evi

A different approach, Doug. Thanks.
Evi

Doug Robbins - Word MVP said:
Hi Evi,

You can use:

Option Explicit
Dim Pasted As Boolean

Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As
MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As
MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As
MSForms.ReturnEffect, ByVal Shift As Integer)
MsgBox "Pasting into this textbox is not allowed"
Pasted = True
End Sub

Private Sub TextBox1_Change()
If Pasted = True Then
TextBox1.Text = ""
Pasted = False
End If
End Sub

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
thought
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top