Can't Undo a Paste Special...

S

src

Hi there,

Recently we've begun to standardize our formats and update all of our
documents at work. I've created a master template which has all of
our boilerplate text, headers and footers.

Oftentimes, a user will open a document based on this template, and
need to copy an paste text from an old document that may have wildy
different Paragraph Styles (which messes up our standard format).
I've created a macro that does a Paste Special and restricts the
Paragraph Styles that are allowed. All Styles that don't match our
master template's get assigned Normal Style.

My problem is that once pasted, there is no Undo available. Here's a
clip of the code:
____
Sub PasteFromOtherDoc()
' Will allow pasting of Text from other (customer) documents but not
pasting of Styles.
' Turns on document protection>styles, pastes, then unprotects.
'
With ActiveDocument
.Styles("1 / 1.1 / 1.1.1").Locked = True
.Styles("1 / a / i").Locked = True
.Styles("Article / Section").Locked = True
.Styles("Balloon Text").Locked = False
.Styles("Block Text").Locked = True
.Styles("Body Text").Locked = True
 
S

Shauna Kelly

Hi

Protecting and unprotecting a document always clears the Undo list, and I
know no way of avoiding that.

I assume you have Word 2003? If so, then protect the document for styles. At
Tools > Protection, turn on "Limit formatting to a selection of styles" and
click the Settings link to identify the styles you want to enable for your
users.

If you do this, when a user pastes text in a style that you have not allowed
in the document, it will be pasted in Normal style.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
S

src

Hi Shauna,

Thanks for the info. I'm turing on Protections, pasting, then turning
off Protection, but as you know it clears the undo list. I thought
about leaving style protection on all the time in the template, but
then it's still possible to paste in a modified Normal style.

I actually left out a bit of the macro code that after it pastes and
unprotects, it then copies the "good" Normal style back from the
template in case it has been corrupted.

I supposed I could disallow pasting of the Normal Style. That way any
new "corrupted" version of the Normal Style would be pasted as
existing "good" Normal Style. Do you think this will work? My
limited testing indicates that it doesn't...

....
Sub PasteFromOtherDoc()
' Will allow pasting of Text from other (customer) documents but not
pasting of Styles.
' Turns on document protection>styles, pastes, then unprotects.
'
With ActiveDocument
.Styles("1 / 1.1 / 1.1.1").Locked = True
.Styles("1 / a / i").Locked = True
.Styles("Article / Section").Locked = True
.Styles("Balloon Text").Locked = False
.Styles("Block Text").Locked = True
.Styles("Body Text").Locked = True
 
S

Shauna Kelly

Hi

I'm not really sure what you're trying to achieve here.
I supposed I could disallow pasting of the Normal Style. That way any
new "corrupted" version of the Normal Style would be pasted as
existing "good" Normal Style.

If I have a document where Normal Style is, say, Arial 10pt blue, and my
document contains a single character (even just a space), and I copy from a
document in which Normal Style is Times New Roman 12pt red, then the text
will paste as Arial 10pt blue.

If the pasted text has any direct formatting, then the text will retain that
direct formatting, but the style will match the destination document.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
S

src

Hi Shauna,

What I'm trying to do is keep wacky paragraph styles from other
documents from being pasted into our official company documents.

In Word 2003, I am able to set the Styles Protection and only allow
certain paragraph styles to be pasted in. Any other styles get forced
to Normal style.

What I just discovered is that this is unsupported in Word 2002, and
we've got almost an even split of 02/03 users here.

So I guess my fundemental issue is: How do I keep unwanted paragraph
styles from being pasted into my doc?
 
S

Shauna Kelly

Hi

For Word 2003 and later, use the styles protection.

For Word 2002 and before, one way is to force everyone to paste as
unformatted text all the time. To do that, intercept the EditPaste command
as described at
Intercepting events like Save and Print
http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm

with a one-line macro like this:

Sub EditPaste
On Error Resume Next
Selection.Range.PasteSpecial DataType:=wdPasteText
End Sub

However, that will prevent pasting pictures, tables etc. You can write more
sophisticated code in the EditPaste sub to allow or prevent pasting whatever
you choose.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
S

src

Thanks for the info, Shauna.

Hm, I've now noticed that when I turn on Styles Protection in 2003, it
then doesn't allow me to do any character formatting either (bold,
italic, underline, etc.).

Is there a way to set Paragraph Styles Protection yet still allow
Character Formatting?

Thanks,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top