MacroBetyár
MacroBetyár

Reputation: 1

How to copy text to clipboard using VBA?

I need a bit help.. How to copy data automatically to the clipboard from the textbox? This is a part of the programm, I already tried a few things..

Sheets("Sheet1").Cells(sor, 1).Value = serial
Sheets("Sheet1").Cells(1, 2).Value = futo
UserForm1.TextBox1.Value = serial
ActiveWorkbook.Save
Application.AlertBeforeOverwriting = False

Dim MyData As DataObject

Set MyData = New DataObject
MyData.SetText UserForm1.TextBox1
MyData.PutInClipboard

End If

Upvotes: 0

Views: 1332

Answers (2)

Aly Abdelaal
Aly Abdelaal

Reputation: 322

if you want to put the value of "serial" variable in clipboard the easiest way to put it in cell and copy the cell

Sheets("Sheet1").Cells(sor, 1).copy

it works well specially if the value is Unicode Characters

Upvotes: 0

Jeremy Hodge
Jeremy Hodge

Reputation: 662

You are referencing the TextBox object, not the Text property of it. Try this.

Sheets("Sheet1").Cells(sor, 1).Value = serial
Sheets("Sheet1").Cells(1, 2).Value = futo
UserForm1.TextBox1.Value = serial
ActiveWorkbook.Save
Application.AlertBeforeOverwriting = False

Dim MyData As New DataObject

MyData.SetText UserForm1.TextBox1.Text
MyData.PutInClipboard

End If

Upvotes: 1

Related Questions