JamJam11
02-13-2011, 03:48 PM
Hi everyone,
This is my first post here! :hi:
I've created a UserForm in Word (I realise this is an Excel thread) and want to add a right click Copy/Paste option that the user can use to copy or paste content in text boxes on the form.
I've searched everywhere for the code to do this and the information on this thread (though for Excel) is the closest I've come to getting something to work.
But...
Can someone help me?
I've added the following code to 'module1':
Sub MakePopUp()
'Remove any old instance of MyPopUp
On Error Resume Next
CommandBars("MyPopUp").Delete
On Error GoTo 0
With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup)
.Controls.Add Type:=msoControlButton, ID:=19
.Controls.Add Type:=msoControlButton, ID:=22
End With
End Sub
And this code to the UserForm1:
Private Sub txtReqDate_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
Application.CommandBars("MyPopUp").ShowPopup
End If
End Sub
In addition to this I added to a Sub called Private Sub UserForm_Initialize() the line:
Call MakePopUp
When I load the UserForm and right click In the text box called 'txtReqDate' I do get a menu popup with 'Copy' and 'Paste' as options but selecting one of the options doesn't do anything i.e. it doesn't copy or paste any text.
I don't receive any error messages.
I've obviously missed something important. Can anyone help me? I've been researching this for days now.
Thanks,
John
This is my first post here! :hi:
I've created a UserForm in Word (I realise this is an Excel thread) and want to add a right click Copy/Paste option that the user can use to copy or paste content in text boxes on the form.
I've searched everywhere for the code to do this and the information on this thread (though for Excel) is the closest I've come to getting something to work.
But...
Can someone help me?
I've added the following code to 'module1':
Sub MakePopUp()
'Remove any old instance of MyPopUp
On Error Resume Next
CommandBars("MyPopUp").Delete
On Error GoTo 0
With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup)
.Controls.Add Type:=msoControlButton, ID:=19
.Controls.Add Type:=msoControlButton, ID:=22
End With
End Sub
And this code to the UserForm1:
Private Sub txtReqDate_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
Application.CommandBars("MyPopUp").ShowPopup
End If
End Sub
In addition to this I added to a Sub called Private Sub UserForm_Initialize() the line:
Call MakePopUp
When I load the UserForm and right click In the text box called 'txtReqDate' I do get a menu popup with 'Copy' and 'Paste' as options but selecting one of the options doesn't do anything i.e. it doesn't copy or paste any text.
I don't receive any error messages.
I've obviously missed something important. Can anyone help me? I've been researching this for days now.
Thanks,
John