With VBA code, I am trying to copy the contents of a text box that is in an Excel worksheet, and paste the contents into a Word document. I have that part working -- however, it is not pasting the formatting of the text along with the text itself. For instance, some of the text is in bold, some is underlined, the font size is not always the same, etc.
Here's what the text box looks like:
When pasted into Word, here is what it looks like:
Here's the code:
Does anyone have any idea how I would get it to paste the text with the formatting?
Here's what the text box looks like:
When pasted into Word, here is what it looks like:
Here's the code:
VBA Code:
Dim TB As Shape
Set TB = ThisWorkbook.Sheets("Sheet1").Shapes("TextBox1")
'This will copy the text in the text box and paste it to the Word document.
'***Currently, it is not pasting the formatting of the text, only the text itself.
Dim MyData As New DataObject
MyData.SetText TB.TextFrame.Characters.Text
MyData.PutInClipboard
objDoc.Range(objDoc.Range.End - 1, objDoc.Range.End).PasteSpecial
'Make the Word document visible.
objWord.Visible = True
Set TB = Nothing
Does anyone have any idea how I would get it to paste the text with the formatting?