2018-09-07
Excel VBA覚書 クリップボード
クリップボードに文字列を貼り付けるときに、貼り付かないケースがあったので、
別の方法を調べてみた。
String型変数 buf の内容をクリップボードに設定するということで・・・
a) DataObjectを使う方法1
Dim cb As Object
Set cb = New DataObject
cb.SetText buf
cb.PutInClipboard
b) DataObjectを使う方法2
With New MSForms.DataObject
.SetText buf
.PutInClipboard
End With
c) TextBoxを使う方法
With CreateObject("Forms.TextBox.1")
.MultiLine = True
.Text = buf
.SelStart = 0
.SelLength = .TextLength
.Copy
End With
If cb.CanPaste Then cb.Paste