Copy Text From Text Box to Clipboard

P

PumaMan

Hi, I'm just learning VBA and I'd like to copy the text that resides within
the text box of a word doc to the clipboard.

I'm copying from a text box instead of a string variable because I want the
text to retain it's formatting when copied (any bullet points, boxes etc.)

Thanks,
Elbio
 
P

PumaMan

Hi Dave,

This is a great link thank you, but it doesn't instruct on how to set the
text within a textbox to the clipboard.

Am I missing something?

Regards,
Elbio
 
A

Amish

A great way to learn these things is to turn on the recorder and try
it out. Not always the most efficient way, but it usually will get you
some code that you can edit down. In this case you would get something
like:

ActiveDocument.Shapes("Text Box 4").Select
Selection.WholeStory
Selection.Copy

Note that the object name is the potentially tricky part in any
automated macro.
The .copy commands throws it to the clipboard - there are some
complexities with the newer office clipboards that contain multiple
entries, but it still works.
 
D

DaveLett

Hi,
The relevant code is:

Dim MyData As DataObject
Dim strClip As String
strClip = "Hi there"

Set MyData = New DataObject

MyData.SetText strClip
MyData.PutInClipboard

You'll need to change the line
strClip = "Hi there"
so that it sets strClip to the value of your textbox.

HTH,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top