• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Assign a result of VBA calculation to clipboard to paste

nagovind

Member
Dear All,

A macro that results with a variable results for each time (its a string)

After running that macro i need to copy that result in the required place manually

Query is, how to copy the end result of a macro in to clipboard so that if i use Ctrl V after running a macro in to the required cell it will get pasted in the required place


Please advise

Regards
Govind
 
Hi Govind ,

Why do you want the result specifically on the Clipboard ? Would it not be easier for the macro to put it into a designated worksheet cell , from where you can copy it to which ever cell you want ?

Narayan
 
Hi Narayan,

Thank you for your reply

Issue is

1. Result of the same macro varies each time it runs
2. Normally i did in the manner you said
3. Each time it run i need to go that cell then copy the data then i need to paste the data in the required cells
4. destination cell/ cells varies each time

So i need a short-cut to keep the result of that macro in to clip board so that after the macro runs i will copy the result in to req. cells using Ctrl v

REDUCING -Going to the cell that contains the result then copy

Regards
Govind
 
Hi nagovind,

May be my suggestion is very small in front of the problem you might be facing.

Adding to Narayan Sir suggestion, why not put the result of macro in a cell and the after that put the last statement as copy that cell and end the macro. Than I think you can use Ctrl+V directly to copy the result in any cell.

Regards,
 
Hi Govind ,

Try this :
Code:
Sub GetTextFromClipboard()
    'For DataObject add reference to Microsoft Forms 2.0 Object Library
    'If you cannot find this library just add a userform and
    'now you will find the library reference. Check it.
   
    Dim objClipBoard        As DataObject
    Dim texttobecopied      As String
    Set objClipBoard = New DataObject
    texttobecopied = "Welcome to the Clipboard"
    With objClipBoard
        .SetText texttobecopied
        .PutInClipboard
    End With
End Sub
Narayan
 
Hi Govind..

Do you have any UserForm in your vba..
If not, just add a UserForm..
as soon as you add a User form, a default reference to "Ms Form Object Libary" will be added in your VBA module..

After that, you can call a Object called DataObject, which has a Method called PutInClipBoard
It put data to Buffer..

Code:
Sub test()
Dim dclip As DataObject

  Const radious = 15
  area = Format(2 * 3.14159265358979 * radious ^ 2, "0.00")

Set dclip = New DataObject
dclip.settext area
dclip.putinclipboard

End Sub

By the way.. Its now in your ClipBoard.. Press Ctrl + V to test.. :)

PS: I am looking for a early binding of that library..without putting User Form in Module..
requesting.. Help :)
 
Dear All,

Thank you very much for all of your reply/ contributions

Below code from Narayan worked well thank you so much
Easy to embed in my existing codes

'For DataObject add reference to Microsoft Forms 2.0 Object Library
'If you cannot find this library just add a userform and
'now you will find the library reference. Check it.

Dim objClipBoard As DataObject
Dim texttobecopied As String
Set objClipBoard = New DataObject
texttobecopied = "Welcome to the Clipboard"
With objClipBoard
.SetText texttobecopied
.PutInClipboard
End With

Regards
Govind
 
Yes checked it.. just few second before my post.. someone already inform this in his comment section.. :)
 
Late binding of Dataobject is bit ugly but can be done. Then you do not have to reference the MS Forms Library. For this, you need ClsID of the object to create.

So following should work:
Code:
Sub LateBoundClipBoard()
Dim objClipBoard As Object
Dim texttobecopied As String
Set objClipBoard = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
texttobecopied = "Welcome to the Clipboard"
With objClipBoard
.SetText texttobecopied
.PutInClipboard
End With
End Sub

We had used this some time back here on the forum as well.
http://chandoo.org/forum/threads/concatenate-two-text-in-vba.5888/#post-32993
[VBA codes there need some fixing up for &#NN; thing and other entries]
 
@shrivallabha
Hi!
I knew that I've gone thru this sometime in the past... but trying to find something from the older topics it's a bit annoying :(
Regards!
 
@shrivallabha
Hi!
I knew that I've gone thru this sometime in the past... but trying to find something from the older topics it's a bit annoying :(
Regards!
Yes. I find it difficult. Sometimes I do google find using usernames and some keywords. Discussions like these tend to remain somewhere at the back of mind so I try to find them as and when possible.
 
@shrivallabha
Hi, buddy!
Yes, it's a pity that @r1c1 never took action to recover the past, our past to which we usually refer to.
Another thing that's missing is the favorite list, but just created a bookmark folder and drop those threads which I want to have handy... once and if I happen to find them. :(
Regards!
 
Back
Top