ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying results to clipboard. Is there a better way ? (https://www.excelbanter.com/excel-programming/415790-copying-results-clipboard-there-better-way.html)

Makissk

Copying results to clipboard. Is there a better way ?
 
Inside a userform there is some code that takes a string, does some
calculation, and produces a result. This result needs to be "sent" to the
clipboard, so that the user - if needing it - can paste it in a cell. For
example, the user enters the 12 first digits of a barcode string, the code
calculates the check digit and then concatenates both in order to create the
entire barcode string.
This string is sent to the clipboard, so that the user can paste it in a cell.

In order to do this, i have declared a variable twice, once as a string and
once again as a New Dataobject:

Dim CodeToEvaluate, CompleteCode As String
Dim CC As Integer
Dim CompleteCodeFinal As New DataObject

After the user enters CodeToEvaluate, some calculation is done for CC to be
found, and then

Let CompleteCode = CodeToEvaluate & CC

Complete code is shown to the user with an Msgbox, and then

CompleteCodeFinal.SetText CompleteCode
CompleteCodeFinal.PutInClipboard

It Works OK. BUT i wonder if there is a more "elegant" way to do this.

Jim Rech

Copying results to clipboard. Is there a better way ?
 
i wonder if there is a more "elegant" way to do this.

No, that's as elegant as it gets.

Dim CodeToEvaluate, CompleteCode As String


FYI, that declares CodeToEvaluate as a variant and CompleteCode as a string.
VB does not do it like C.

--
Jim
"Makissk" wrote in message
...
| Inside a userform there is some code that takes a string, does some
| calculation, and produces a result. This result needs to be "sent" to the
| clipboard, so that the user - if needing it - can paste it in a cell. For
| example, the user enters the 12 first digits of a barcode string, the code
| calculates the check digit and then concatenates both in order to create
the
| entire barcode string.
| This string is sent to the clipboard, so that the user can paste it in a
cell.
|
| In order to do this, i have declared a variable twice, once as a string
and
| once again as a New Dataobject:
|
| Dim CodeToEvaluate, CompleteCode As String
| Dim CC As Integer
| Dim CompleteCodeFinal As New DataObject
|
| After the user enters CodeToEvaluate, some calculation is done for CC to
be
| found, and then
|
| Let CompleteCode = CodeToEvaluate & CC
|
| Complete code is shown to the user with an Msgbox, and then
|
| CompleteCodeFinal.SetText CompleteCode
| CompleteCodeFinal.PutInClipboard
|
| It Works OK. BUT i wonder if there is a more "elegant" way to do this.




All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com