+ Reply to Thread
Results 1 to 2 of 2

Thread: Macro to clear a document if unauthorised access

  1. #1
    Registered User
    Join Date
    12-13-2007
    Posts
    10

    Macro to clear a document if unauthorised access

    Hi all,

    I work for myself and occasionally I hire one off consultants to assist when I get busy. I usually send them a copy of my templates to ensure they are consistent with my templates and fit on my letterhead etc.

    I was wondering is it possible to write a macro which on opening the word document searches for a specific phrase (ie. the business name) and if this exists in the text of the document the macro ends.

    If however the business name has been deleted and replaced by their own business name, I'd like the macro to search for my business name, not find it then delete everything, save the document and close the document.

    Is something like this possible?

    Any suggestions would be great.

    Thanks for your help.

  2. #2
    Registered User
    Join Date
    12-13-2007
    Posts
    10

    Re: Macro to clear a document if unauthorised access

    Hi again,

    I've sorted it out. I used the following:

    Private Sub Document_Open()
    Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "BUSINESS NAME"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchByte = False
            .CorrectHangulEndings = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = False
            .MatchFuzzy = False
        .Execute
        Selection.HomeKey Unit:=wdStory
        If Selection.Find.Found = False Then Call Delete
        End With
    End Sub
    and

        Selection.WholeStory
        Selection.Delete Unit:=wdCharacter, Count:=1
        ActiveDocument.Save
        ActiveDocument.Close
    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0