Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default copy-paste in a userform

i would like to know how i can activate
the right mouse button menu (copy, cut, paste etc)
when i am inserting data in a userform's textbox
thanx


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default copy-paste in a userform

Look he

http://www.mvps.org/word/FAQs/Userfo...tClickMenu.htm

RBS

"Hatzipavlis Stratos" wrote in message
...
i would like to know how i can activate
the right mouse button menu (copy, cut, paste etc)
when i am inserting data in a userform's textbox
thanx



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default copy-paste in a userform

1. Add a new userform called Userform1
2. Add a textbox called TextBox1
3. Paste the following into the userform's code module:

1. Add a new userfor m

'------------------------------------------------
Option Explicit

Private Const strRIGHTCLICKMENU_NAME As String = "MyRightClickMenu"

Private Sub UserForm_Initialize()
CreateRightClickMenu
End Sub

Private Sub UserForm_Terminate()
KillRightClickMenu
End Sub

Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
Excel.Application.CommandBars(strRIGHTCLICKMENU_NA ME).ShowPopup
End If

End Sub

Private Function CreateRightClickMenu() As Boolean

On Error Resume Next
Excel.Application.CommandBars(strRIGHTCLICKMENU_NA ME).Delete
On Error GoTo 0

With CommandBars.Add(strRIGHTCLICKMENU_NAME, msoBarPopup)

With .Controls.Add(msoControlButton)
.Caption = "Cut"
.FaceId = 21
.OnAction = "MenuCut"
End With

With .Controls.Add(msoControlButton)
.Caption = "Copy"
.FaceId = 19
.OnAction = "MenuCopy"
End With

With .Controls.Add(msoControlButton)
.Caption = "Paste"
.FaceId = 22
.OnAction = "MenuPaste"
End With

End With

CreateRightClickMenu = True

End Function

Private Sub KillRightClickMenu()

On Error Resume Next
Excel.Application.CommandBars(strRIGHTCLICKMENU_NA ME).Delete
On Error GoTo 0

End Sub
'------------------------------------------------

4. Add a standard module and paste in the following code:

'------------------------------------------------
Option Explicit

Public Sub MenuCut()

Dim strTextToAdd As String
Dim DataObject1 As DataObject
Dim ctlActive As MSForms.Control

On Error GoTo Err_Handler

If UserForm1.Visible = False Then

Unload UserForm1
Exit Sub

End If

Set DataObject1 = New DataObject

Set ctlActive = UserForm1.ActiveControl

Do Until Not TypeOf ctlActive Is MSForms.Frame
Set ctlActive = ctlActive.ActiveControl
Loop

strTextToAdd = ctlActive.SelText

If Len(strTextToAdd) 0 Then

With DataObject1
.SetText strTextToAdd
.PutInClipboard
End With

ctlActive.SelText = vbNullString

End If

Err_Handler:

Set DataObject1 = Nothing

End Sub

Public Sub MenuCopy()

Dim strTextToAdd As String
Dim DataObject1 As DataObject
Dim ctlActive As MSForms.Control

On Error GoTo Err_Handler

If UserForm1.Visible = False Then

Unload UserForm1
Exit Sub

End If

Set DataObject1 = New DataObject

Set ctlActive = UserForm1.ActiveControl

Do Until Not TypeOf ctlActive Is MSForms.Frame
Set ctlActive = ctlActive.ActiveControl
Loop

strTextToAdd = ctlActive.SelText

If Len(strTextToAdd) 0 Then

With DataObject1
.SetText strTextToAdd
.PutInClipboard
End With

End If

Err_Handler:

Set DataObject1 = Nothing

End Sub
Public Sub MenuPaste()

Dim strTextToAdd As String
Dim DataObject1 As DataObject
Dim ctlActive As MSForms.Control

On Error GoTo Err_Handler

If UserForm1.Visible = False Then

Unload UserForm1
Exit Sub

End If

Set DataObject1 = New DataObject

DataObject1.GetFromClipboard
strTextToAdd = DataObject1.GetText()

If Len(strTextToAdd) 0 Then

Set ctlActive = UserForm1.ActiveControl

Do Until Not TypeOf ctlActive Is MSForms.Frame
Set ctlActive = ctlActive.ActiveControl
Loop

ctlActive.SelText = strTextToAdd

End If

Err_Handler:

Set DataObject1 = Nothing

End Sub
'------------------------------------------------

5. Run the userform, type some text in the textbox, right click and
try out the menu items.



"Hatzipavlis Stratos" wrote in message ...
i would like to know how i can activate
the right mouse button menu (copy, cut, paste etc)
when i am inserting data in a userform's textbox
thanx

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't Copy and Paste or Paste Special between Excel Workbooks wllee Excel Discussion (Misc queries) 5 April 29th 23 03:43 AM
Excel cut/Paste Problem: Year changes after data is copy and paste Asif Excel Discussion (Misc queries) 2 December 9th 05 05:16 PM
Long Time Delay To Paste From UserForm To Sheet Minitman Excel Worksheet Functions 7 December 6th 05 12:30 AM
copy userform Oldjay New Users to Excel 2 November 3rd 05 02:00 AM
how2 paste into a userform text box? jimredfield[_5_] Excel Programming 2 October 18th 03 12:19 AM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"