Advertisement

03.09.2007 at 01:49AM PST, ID: 22438613
[x]
Attachment Details

VBA copy and paste functions - DataObject GetFromClipboard / PutInClipboard

Asked by ryan_uk in VB Objects, Visual Basic Programming, VB Controls

Tags: vba, copy, getfromclipboard, paste

Hello all,

I have a form which contains a number of textboxes and other such objects.  Within this form I have a listbox which is displayed when the right-mouse is clicked.  This list displays the options "Copy" and "Paste".  The problem is that I cannot seem to code the right functions for these options.

I have tried using SendKeys.  The copy function works fine, however when I use SendKeys for paste it will only ever paste into the first textbox as defined by the tab order, which of course renders the function useless.

I found an alternative which is the DataObject PutInClipboard and GetFromClipboard but the copy source and target objects are coded rather than user selectable.  The code follows:

Dim MyData As DataObject

Private Sub ListBox1_Click()

If ListBox1.Value = "Copy" Then

Set MyData = New DataObject
MyData.SetText TextBox1.Text   <<
MyData.PutInClipboard

ElseIf ListBox1.Value = "Paste" Then

Set MyData = New DataObject

MyData.GetFromClipboard
TextBox2.Text = MyData.GetText(1) <<

End If

ListBox1.Visible = False

End Sub

The problem is the use of TextBox1.Text and TextBox2.Text  (I've used << to indicate this).  These need to be variable depending on what box the user has called the listbox from.

Any help appreciated!Start Free Trial
[+][-]03.09.2007 at 03:16AM PST, ID: 18686386

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Objects, Visual Basic Programming, VB Controls
Tags: vba, copy, getfromclipboard, paste
Sign Up Now!
Solution Provided By: R_Rajesh
Participating Experts: 1
Solution Grade: B
 
 
[+][-]03.09.2007 at 03:39AM PST, ID: 18686466

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.09.2007 at 03:59AM PST, ID: 18686532

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32