Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I detect user deleting/cutting text? URGENT (Word 2002)

    Hi,

    I have a document which contains a section break with a header and footer. Users have been accidentally deleting the sections be selecting an entire line of text (including the section break) then either cutting or deleting it.

    Is there any way using VBA that I can detect and handle in the code a deletion or cut.

    This is an urgent problem, so any help really would be much appreciated [img]/forums/images/smilies/smile.gif[/img]

    Thanks,

    Chris

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I detect user deleting/cutting text? URGENT (Word 2002)

    You can trap the EditCut sub, but what do you test for? If the
    text they are cutting is static, you can test for that. But if not????

    Something like this:
    Sub EditCut()
    If Selection.Text Like "*nefarious text*" Then
    'Also test to see if they got the section break too
    With Selection.Find
    .ClearFormatting
    .Text = "^b"
    .Forward = True
    .Wrap = wdFindContinue
    .Execute
    If .Found Then
    MsgBox "You can't delete this section break."
    Selection.Collapse wdCollapseStart
    End If
    End With
    Else
    Selection.Cut
    End If
    End Sub

    And you can trap the delete key ala the Klaus technique:

    KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
    Command:="StopThatDeletion", _
    KeyCode:=wdKeyDelete

    Caution advised. <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How do I detect user deleting/cutting text? URGENT (Word 2002)

    I can't think of a practical way to stop a delete or cut, but you could give the user a "restore section break" macro so they can put it back in. Or hope that this is the kind of mistake they only make once. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  4. #4
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I detect user deleting/cutting text? URGENT (Word 2002)

    Thanks for the replies.

    I would love to be able to put together a "restore section break", but I have no idea how to go about it!

    It seems like the perfect solution.

    Any ideas/help would be much appreciated [img]/forums/images/smilies/smile.gif[/img]

    Thanks,

    Chris

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How do I detect user deleting/cutting text? URGENT (Word 2002)

    Easiest to save it as an AutoText in the associated template (if there is one!) and Insert it as needed (making sure to use the RichText setting). Or, if you can stash a template out on the network somewhere, you could temporarily add it to the Add-ins collection, insert from there, and then uninstall it.

    If you don't have the luxury of a place to store AutoText, you'll have to use code to insert the break and then, in that section, re-do the headers and footers. Easiest would be to record a macro of yourself doing that. Would be good to go through the Page Setup dialog to make sure your choice of different first page, etc., is reflected in the new section.

    I realize this is rather cryptic and rushed <img src=/S/smile.gif border=0 alt=smile width=15 height=15> so if this doesn't make any sense, hopefully someone will chime in!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •