Extracting data direct from the clipboard, to avoid Select and Paste

richarddawson

Board Regular
Joined
Oct 18, 2014
Messages
87
I want to avoid Copy and Paste, but I have to pick up a string from a third-party website. I am trying to do this by taking a value directly off the clipboard, using this procedure.

Public tfrString As String
Public dataObj As New MSForms.DataObject

Function clipIt()
Dim jString As String
dataObj.GetFromClipboard
tfrString = dataObj.GetText
End Function

This works fine as a standalone, but when I try to use it elsewhere –

Call clipIt
And then use tfrString

I get an error message
“DataObject: GetText OpenClipBoard Failed”.

Can anyone suggest why, please?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What about something like this instead?

Code:
Function clipIt() As String
    Dim clipObj As New MSForms.DataObject
    Dim jString As String

    clipObj.GetFromClipboard
    jString = clipObj.GetText
    clipIt = jString
    Set clipObj = Nothing
End Function



BTW, I recommend you use code tags for clarity when posting code
attachment.php

attachment.php
 
Upvote 0
Maybe this:

Code:
Function clipIt()
Dim dataObj As New MSForms.DataObject
dataObj.GetFromClipboard
clipIt = dataObj.GetText
End Function

Sub toGet()
MsgBox clipIt
End Sub
 
Upvote 0
Thanks Akuini,

Very odd! It works fine on an older machine, but not a more modern one. Both are running Windows 10 & Office 365.

The older one is an HP, running 4 cores; the modern a Zoostorm, running 8 virtual - but I have tried restricting it to 4 cores - still no joy.

Any ideas?
 
Upvote 0
Thanks Akuini,

Very odd! It works fine on an older machine, but not a more modern one. Both are running Windows 10 & Office 365.

The older one is an HP, running 4 cores; the modern a Zoostorm, running 8 virtual - but I have tried restricting it to 4 cores - still no joy.

Any ideas?

I have no idea why that happen.
Let's try this one instead:

Code:
Function clipIt()
Dim dataObj As DataObject

Set dataObj = New DataObject
dataObj.GetFromClipboard
clipIt = dataObj.GetText
End Function

Note:
For using MSForms.DataObject in your code you need library “Microsoft Forms 2.0 Object Library”.
(in Visual Basic Editor (VBE) window, go to the Tools menu and select References from the drop down menu.)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top