Clipboard Question

Huey462

Board Regular
Joined
Jul 25, 2011
Messages
147
I have a button that grabs data from several fields, formats them, puts that text string into a new field and copies it to the clipboard with the docmd ac.copy (not at that computer right now so the command may not be exactly right). My question is, rather than go through the step of pasting the data to a text field and then copying to the clipboard, is there a way to send the text string directly to the clipboard?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
From https://stackoverflow.com/questions/14219455/excel-vba-code-to-copy-a-specific-string-to-clipboard

This macro uses late binding to copy text to the clipboard without requiring you to set references. You should be able to just paste and go:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">
Code:
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CopyText[/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#303336][FONT=inherit]Text [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]String[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
    [/FONT][/COLOR][COLOR=#858C93][FONT=inherit]   'VBA Macro using late binding to copy text to clipboard.[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
    [/FONT][/COLOR][COLOR=#858C93][FONT=inherit]   'By Justin Kay, 8/15/2014[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
    [/FONT][/COLOR][COLOR=#101094][FONT=inherit]   Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] MSForms_DataObject [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Object[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
    [/FONT][/COLOR][COLOR=#101094][FONT=inherit]   Set[/FONT][/COLOR][COLOR=#303336][FONT=inherit] MSForms_DataObject [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CreateObject[/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
   MSForms_DataObject[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]SetText Text
   MSForms_DataObject[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]PutInClipboard
    [/FONT][/COLOR][COLOR=#101094][FONT=inherit]   Set[/FONT][/COLOR][COLOR=#303336][FONT=inherit] MSForms_DataObject [/FONT][/COLOR][COLOR=#303336][FONT=inherit]=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]Nothing[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]End [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub

[/FONT][/COLOR]</code>[COLOR=#242729][FONT=Arial]' Usage:[/FONT][/COLOR]
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">[COLOR=#101094][FONT=inherit]
Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CopySelection[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
   CopyText Selection[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Text
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]End [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR]</code>
 
Last edited:
Upvote 0
65StringJazzer,

In looking at part of your code here:
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; line-height: inherit; border: 0px; font-variant: inherit; font-stretch: inherit; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">[COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CopySelection[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR][COLOR=#303336][FONT=inherit]
   CopyText Selection[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Text
[/FONT][/COLOR][COLOR=#101094][FONT=inherit]End [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR]</code>
The use of "Selection" seems to imply that this code may be geared toward Microsoft Excel.
Note that this question was posted in the "Microsoft Access" forum, so I think that they were looking for code that works from Access, not Excel.
I don't think that "Selection" works in Access. But perhaps some minor modifications can work to make it work in Access too?
 
Upvote 0
The use of "Selection" seems to imply that this code may be geared toward Microsoft Excel.
Note that this question was posted in the "Microsoft Access" forum, so I think that they were looking for code that works from Access, not Excel.
Thank you for that, I clicked on this from the Zero Responses query and did not notice it was in the Access forum. I have no experience writing VBA for Access. I do not know how to address "a text field" in Access.
 
Upvote 0
Thank you for that, I clicked on this from the Zero Responses query and did not notice it was in the Access forum.
Yes, a lot of people miss that listing shows questions from all forums, not just the Excel one.
The last column in that list shows you which forum the question is located in.
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

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