Amir was telling us:
Amir nous racontait que :
Hi,
Is there any way to capture the Paste event to Word, so that each
time a user pastes a text into Word a macro will run?
You can hijack the built-in paste methods that Word uses (Not that the sub
must be names as they are named here):
'_______________________________________
Sub EditPaste()
MsgBox "Trying to paste, are you?"
End Sub
'_______________________________________
'_______________________________________
Sub EditPasteSPecial()
MsgBox "Trying to paste special, are you?"
End Sub
'_______________________________________
If so, How can I check if the pasted data is text, and in case it's a
For this, you need to check the content of the clipboard:
See
http://word.mvps.org/FAQs/MacrosVBA/ManipulateClipboard.htm
for some information regarding basic requirements.
As for testing the clipboard content, try something like this:
'_______________________________________
Dim MyData As DataObject
Dim strClip As String
Set MyData = New DataObject
MyData.GetFromClipboard
If MyData.GetFormat(1) Then
'Thiere is text on the clipboard
strClip = MyData.GetText
Else
MsgBox "Sorry, no text in the clipboard"
End If
'_______________________________________
text, select the pasted text and do some changes in it using VBA
code, e.g. Selection.FormattedText.Font.Name = "Times New Roman" ?
For this last part, you are going to have to use your imagination to get the
user text from the clipboard to the document and manipulate it...
Use the Range object to insert the text string form the clipboard to the
document. Remember that a table will register as text ...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org