Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Capturing Paste event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amir - 09 Jul 2005 07:12 GMT
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?

If so, How can I check if the pasted data is text, and in case it's a text,
select the pasted text and do some changes in it using VBA code, e.g.
Selection.FormattedText.Font.Name = "Times New Roman" ?

I'm using Office2000.

Kind Regards,
Amir.
Anne Troy - 09 Jul 2005 15:47 GMT
For some reason, I don't think you can capture that event, but here's what
most people do:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=18
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com

> Hi,
>
[quoted text clipped - 9 lines]
> Kind Regards,
> Amir.
Amir - 09 Jul 2005 16:31 GMT
Hi Anne,

That's not exactly what I was looking for, but it gives me the idea of using
a different macro in order to paste that text instead of capturing the paste
event. It's less convinient but it should work.

Thank you.

Kind Regards,
Amir.

> For some reason, I don't think you can capture that event, but here's what
> most people do:
[quoted text clipped - 19 lines]
>> Kind Regards,
>> Amir.
Jean-Guy Marcil - 09 Jul 2005 16:37 GMT
Anne Troy was telling us:
Anne Troy nous racontait que :

> For some reason, I don't think you can capture that event, but here's

Yes you can, see my reply in this same thread.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Jean-Guy Marcil - 09 Jul 2005 16:31 GMT
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 ...

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Amir - 10 Jul 2005 03:00 GMT
Thank you very much!

That's what I was looking for.

Regards!

> Amir was telling us:
> Amir nous racontait que :
[quoted text clipped - 53 lines]
> Use the Range object to insert the text string form the clipboard to the
> document. Remember that a table will register as text ...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.