Hello,
I'm looking to create a macro to paste whatever it is in the clipboard with
unformatted text with red font color. How can this be accomplished?
Thanks so much!
First, in the VBA editor, go to Tools > References and put a checkmark
in the box next to "Microsoft Forms 2.0 Object Library". Then insert
this macro:
Sub demo()
Dim myRg As Range
Dim myDO As DataObject
Dim myText As String
On Error GoTo bye
Set myRg = Selection.Range
Set myDO = New DataObject
myDO.GetFromClipboard
myText = myDO.GetText(1)
With myRg
.Text = myText
.Font.Color = wdColorRed
End With
bye:
Set myRg = Nothing
End Sub
This was my second choice. First I tried simply
MyRg.PasteSpecial DataType:=wdPasteText
but, unlike setting MyRg.Text, this didn't cause the range to expand
to include the pasted text. It pasted OK, but then I didn't have the
correct range to apply the font color.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.