PDA

View Full Version : [SLEEPER:] MS Word overwrite Paste Options:



Norsak
04-30-2022, 05:01 PM
Hi,

I want to restrict a document so that all paste actions result in plain text being added to the document.

I am able to over-write the default behaviour of CTRL + V using this procedure:


Sub EditPaste()
Selection.PasteAndFormat (wdFormatPlainText)
End Sub


I am now trying to restrict the Paste Options. (under right-click)
I haven't had any luck googling a good answer.
Does anyone know how to restrict Paste Options to only show "Keep Text Only"

Aussiebear
04-30-2022, 06:05 PM
Assuming you are using a Microsoft system, In Word, select Options...Advanced. Under Cut, copy, and paste, set all the "Pasting" settings to Keep Text Only

Norsak
04-30-2022, 07:43 PM
Assuming you are using a Microsoft system, In Word, select Options...Advanced. Under Cut, copy, and paste, set all the "Pasting" settings to Keep Text Only

I'm pretty sure that would change the behaviour of the MS Word application on my computer.
To clarify: I'm looking to add VBA to a document, so that if someone else opens that document (on their computer), they are restricted to pasting text-only

Aussiebear
04-30-2022, 10:57 PM
Then I suggest you record the method of completing that which was indicated to Post #2 and then upload the code here so that we can modify it to suit your needs.

Chas Kenyon
05-01-2022, 10:07 AM
Note that there is no way you can be sure that another user will allow your code to run.

Norsak
05-02-2022, 03:56 AM
Note that there is no way you can be sure that another user will allow your code to run.

This I kind of already solved.
I run this procedure before I save the document:



Sub hideAll()
ThisDocument.Range.Font.Hidden = True
End Sub


The document then has a picture-button-macro that triggers the reverse action.
..They need to enable macros to see the form

Norsak
05-02-2022, 04:33 AM
Then I suggest you record the method of completing that which was indicated to Post #2 and then upload the code here so that we can modify it to suit your needs.

I'm not quite ready to go down the path you have suggested.
This means using VBA to change the default behaviour of MS Word on the client computer.
That feels invasive. (might be a genius work around, where nothing else will work)

Ideally I'm seeking a solution that only affects the document in question.


This code:


Sub EditPaste()
Selection.PasteAndFormat (wdFormatPlainText)
MsgBox "testing"
End Sub

Works because EditPaste is a builtin method/macro that is triggered by CTRL + V

The problem is that EditPaste is not triggered when the user chooses Paste Options:
And I have no idea what is triggered when they use Paste Options:

If someone knows how to inject code when the user chooses Paste Options: ... that would be very helpful

Aussiebear
05-02-2022, 04:37 AM
This means using VBA to change the default behaviour of MS Word on the client computer.
That feels invasive. (might be a genius work around, where nothing else will work)

Ideally I'm seeking a solution that only affects the document in question.

If someone knows how to inject code when the user chooses Paste Options: ... that would be very helpful

As Chas Kenyon has suggested it cannot be done. Further as you have intimated you are trying to change the default behaviour on a client computer and that IS invasive.