MS Office Forum / Word / Programming / March 2007
Can't Undo a Paste Special...
|
|
Thread rating:  |
src - 15 Feb 2007 23:48 GMT 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 . . . .Styles("Normal (Web)").Locked = False .Styles("Normal Indent").Locked = False .Protect Password:="", NoReset:=False, Type:=wdNoProtection, _ UseIRM:=False, EnforceStyleLock:=True End With Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Unprotect ____
It appears that once I Unprotect the document, the Undo stack is cleared.
Is there any way I can keep the Undo stack so that my users can reverse any inadvertant pastes?
Thanks!
Shauna Kelly - 16 Feb 2007 00:50 GMT 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
> Hi there, > [quoted text clipped - 44 lines] > > Thanks! src - 20 Feb 2007 19:11 GMT 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 . . . .Styles("Normal (Web)").Locked = TRUE '<< Changed from False .Styles("Normal Indent").Locked = False .Protect Password:="", NoReset:=False, Type:=wdNoProtection, _ UseIRM:=False, EnforceStyleLock:=True End With
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Unprotect
'Copy Normal style back over in case it was changed. sSourceTemplate = Options.DefaultFilePath(wdStartupPath) & "\GlobalMacros.dot" ' name and path of global template sTargetDoc = ActiveDocument.FullName 'generates error if no document
Application.OrganizerCopy Source:=sSourceTemplate, _ Destination:=sTargetDoc, Name:="Normal", Object:= _ wdOrganizerObjectStyles
ActiveDocument.AttachedTemplate.Saved = True 'Keeps from asking if you'd like to save the template. End Sub ....
Thanks, Matt
On Feb 15, 5:50 pm, "Shauna Kelly" <ShaunaKe...@SendNoSpamToShaunaKelly.com> wrote:
> Hi > [quoted text clipped - 12 lines] > > Shauna Kelly. Microsoft MVP.http://www.shaunakelly.com/word Shauna Kelly - 21 Feb 2007 12:23 GMT 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
> Hi Shauna, > [quoted text clipped - 78 lines] >> >> Shauna Kelly. Microsoft MVP.http://www.shaunakelly.com/word src - 23 Feb 2007 00:55 GMT 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?
On Feb 21, 5:23 am, "Shauna Kelly" <ShaunaKe...@SendNoSpamToShaunaKelly.com> wrote:
> Hi > [quoted text clipped - 98 lines] > > >> Shauna Kelly. Microsoft MVP.http://www.shaunakelly.com/word Shauna Kelly - 23 Feb 2007 06:32 GMT 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
> Hi Shauna, > [quoted text clipped - 120 lines] >> >> >> Shauna Kelly. Microsoft MVP.http://www.shaunakelly.com/word src - 21 Mar 2007 02:34 GMT 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
On Feb 23, 12:32 am, "Shauna Kelly" <ShaunaKe...@SendNoSpamToShaunaKelly.com> wrote:
> Hi > [quoted text clipped - 19 lines] > > Shauna Kelly. Microsoft MVP.http://www.shaunakelly.com/word
|
|
|