Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Protect Header/Footer (Word 2000 (SR-1) NT)

    Recently I got lots of help making code for preventing users from opening header/footer. This is originally collected from the following site:

    http://www.mvps.org/word/FAQs/Customizatio...d2000Header.htm
    Originally this code was having a routine:

    Private Sub Document_Close()
    Set wdApp = Nothing
    End If
    End Sub

    Does anyone have a clue why?

    I have experienced that if I use this procedure, the prevention is disabled when I cancel the document instead of closing it.

    Thanks for suggestions and answers

    Bjorn

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Protect Header/Footer (Word 2000 (SR-1) NT)

    Hi Bjorn,

    The purpose of the:
    Set wdApp = Nothing

    is to follow good practice and destroy the application object that was created in the Document_New/Document_Open event procedures (if I'm recalling correctly).

    The reason you're losing the protection is that the Document_Close event fires before the prompt to save changes shows on your screen. So if you cancel (thus keeping the document open), the application object has been destroyed as a result of the Document_Close code running, and the SelectionChange event doesn't get tracked anymore.

    Try inserting:
    ActiveDocument.Save

    as the first line of code in the Document_Close sub.

    This way, the document will simply close, without the prompt to save changes, so the Cancel option won't be available.

    This does assume by the way, that the document has already previously been saved and named - if it hasn't been, then you'll need some more code to handle that.

    Gary

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Protect Header/Footer (Word 2000 (SR-1) NT)

    Thanks Gary for a very quick answer.

    I have overcome this by not using the Document_close procedure. Thus not setting wpApp to nothing. But what harm does it make?

    And why does the Document_Open code not function when opening such a document from SharePoint, that is through an URL address? Even though the other code is functioning OK!

    Thanks Gary!

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Protect Header/Footer (Word 2000 (SR-1) NT)

    <P ID="edit"><FONT SIZE=-1>Edited by Gary Frieder on 17-Aug-01 05:57.</FONT></P>Hi again,

    The downside to not destroying the object reference, in this case, is that Word may still be carrying around in its memory, the space relegated to the application object. If the document were opened many times within a given Word session, this could in theory cause Word some problems as you'd start to accumulate lots of these wdApplication objects in memory.

    I'm not really clear on this myself, but my working assumption is that simple object references such as:

    Set myTable = ActiveDocument.Tables(1)

    get destroyed when the procedure they were declared in stops running. So while not essential to explicitly Set them to Nothing, it's just good housekeeping.

    An object reference to wdApplication is a different sort of thing, because it continues to exist, even after the procedure that created it has stopped running. That's why it's being explicitly destroyed in the Document_Close.
    So I'd say in this case, it's not a good idea to omit the Document_Close.

    I'm not familiar with SharePoint so can't help with that.

    Gary

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Protect Header/Footer (Word 2000 (SR-1) NT)

    Thanks again Gary. I was a bit slow this time, it was caused by a hanging/crash of the machine, may be because Word's memory got full, due to the application object, which I have experienced earlier also.

    Well, to the problem with opening from SharePoint:
    SharePoint is Microsoft's document control system(tool): http://www.microsoft.com/sharepoint/

    The tool is able to put documents under strict control, keeping track of issue/version umbers etc. and much more.

    Opening the document from SharePoint is like opening it in Internet Explorer(http://....) I only get the question whether I will accept the macros to which I have to answer Yes, of course.

    I will have to try out setting wpApp to nothing.

    Regarding the SharePoint problem I will investigate in the days to come.

    Best regards bjorn and have a nice week end.

    bjorn

Posting Permissions

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