David said:
I am trying to create a word macro that pastes whatever is on the clipboard
into the screentip box - can anyone suggest a way of doing it. I have tried
the 'Record macro Function' but, when I play it back again it does not paste
what is on the clipboard but what was on the clipboard when i was recording.
I am using Microsoft Word 2004.
What screentip are you refering to?
For now I will assume that you mean the one for hyperlinks.
Here is some code that shows you what you can do in order to manipulate the
clipboard. You will need to set some referemnce in your project. For more on
this see:
http://word.mvps.org/FAQs/MacrosVBA/ManipulateClipboard.htm
Option Explicit
Sub CreateHyperlink()
Dim strHTTP As String
strHTTP = InputBox("Type the Web hyperlink address.", "Create Hyperlink")
If strHTTP = "" Then
MsgBox "No hyperlink created.", vbInformation, "Cancelled"
Exit Sub
End If
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
strHTTP, SubAddress:="", ScreenTip:=GetClipboardText, _
TextToDisplay:=strHTTP
End Sub
Function GetClipboardText() As String
Dim MyData As DataObject
Set MyData = New DataObject
MyData.GetFromClipboard
If MyData.GetFormat(1) Then
'There is text on the clipboard
GetClipboardText = MyData.GetText
Else
MsgBox "Cannot create screentip, no text in the clipboard", _
vbExclamation, "No screentip created"
End If
End Function