PDA

View Full Version : Macro in template to force pasting without formatting?



thunderstorm
10-16-2009, 02:03 AM
I need a macro in a template to intercept a user trying to paste text into a new document (based on the template) and force the pasted text to be non formatted (i,e, use Selection.PasteSpecial DataType:=wdPasteText).

I managed to assign this to my own keyboard shortcut, but I need this to be in a template I send to other users and want it to happen when they try to paste themselves- without them having to set up their own macro & shortcut/ use the paste special action.

Basically they're complaining when they paste text it doesnt take on the document's text formatting.

Is this even possible?

Thanks :)

fumei
10-16-2009, 10:12 AM
Force them to execute code when they are pasting directly? No, this is not possible.

It is possible to have your procedure (executed via your shortcut) in the template, but any given user may use it...or not.

That being said, you CAN - to an extent - "intercept" a Paste operation by writing your own Sub EditPaste. For example:
Sub EditPaste()
MsgBox "You are trying to paste."
End Sub
If this is in the document, then any paste operation will execute it. In the example above, obviously no paste actually occurs, as the only instruction is the messagebox. In other words, they can NOT paste.

Substitute your code for the MsgBox instruction.

"Basically they're complaining when they paste text it doesnt take on the document's text formatting."

This should not be happening if there is proper use of Styles.