Consulting

Results 1 to 7 of 7

Thread: Solved: Document_Open Event

  1. #1
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location

    Solved: Document_Open Event

    I dont use Word often but I was wondering if this was possible. I can't seem to figure out if there are Auto_Open / Auto_Close for Word. Document Open?
    I wanted to hide some of the command bars when a specific Word Doc is opened and then unhide on closing. (Like I can easily figure out in excel) I can get it to Work using buttons from Control Toolbox. Any way to make it happen on an open event?

    Justin Labenne

  2. #2
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Sure.
    Put the code in ThisDocument and make it"

    [vba]Private Sub Document_Open()[/vba]

    Now, if you're using a template, you'll want to ALSO put the code into:

    [vba]Private Sub Document_New()[/vba]

    Please don't forget to put the toolbars back on:

    [vba]Private Sub Document_Close()[/vba]
    ~Anne Troy

  3. #3
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    Dont Know what im missing. Here is the code I have in the ThisDocument code module:
    [vba]Private Sub Document_Close()
    With Application
    .CommandBars("Standard").Visible = True
    .CommandBars("Formatting").Visible = True
    .CommandBars("Drawing").Visible = True
    End With
    End Sub
    ''''
    Private Sub Document_Open()
    With Application
    .CommandBars("Standard").Visible = False
    .CommandBars("Formatting").Visible = False
    .CommandBars("Drawing").Visible = False
    End With
    End Sub[/vba]

    I close the Document and reopen and all toolbars are still visible? Im sure its me. Never done VBA in Word ever.

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    They both work just fine for me.

    Dude...you got your Macro security set to high?
    Better set it to medium or low BEFORE you open the document.

    ~Anne Troy

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    By the way....

    In the VBE, normal.dot is Word's default template. Anything you put in there happens all the time. However, normal.dot doesn't have a document_open when you launch Word; it only has a document_new.

    So, make sure you're putting this in ThisDocument of the DOCUMENT, and not in Normal.dot.

    Dot it? I mean...got it?
    Hee hee...
    I crack myself up.
    ~Anne Troy

  6. #6
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    Yes, that was absolutely it. Right before I came back to check this post I realized i had never used Macros for Word here at home, I had also never been prompted to Enable. Thank you so much much for your help. It worked after I stopped and thought for a second. (Actually an Hour)

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    It works?

    GREAT!!

    :cool
    ~Anne Troy

Posting Permissions

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