Macro To Show Messagebox On Open Doc

  • Hi All,


    Just struggling a little bit trying to get a Word macro that automatically runs a msgbox when the document is opened. Essentially its for a form that users will click on a link for - i want a messagebox with a warning to open when they open the doc.


    Here is what i have tried thus far:

    Code
    Private Sub Document_Open()
    MsgBox "Ensure that you get Manager authorisation"
    End Sub


    Any advice would be greatly appreciated!
    Thanks,
    Mike

  • Re: Macro To Show Messagebox On Open Doc


    Mike,


    There are 2 ways to run code at startup.
    using auto_open (code located in a module)


    Code
    Sub auto_open()
    
    
        MsgBox "Ensure that you get Manager authorisation"
    
    
    End Sub


    The other is using Workbook open. (code in Thisworkbook)


    Code
    Private Sub Workbook_Open()
        MsgBox "Ensure that you get Manager authorisation"
    End Sub


    Hope this helps you.
    Best regards.
    Kurt.

  • Re: Macro To Show Messagebox On Open Doc


    What happens at the moment ??


    I just pasted the macro into word here and it worked fine...the only reason I can see for it not working would be if the security setting in word is too high...the options in my version are


    Very high
    High
    Medium
    Low


    If the macro you have is unsigned (probably the case) the you will need this at medium...medium warns the user that the documents contains macros and asks them whether they should disable / enable them for each document.


    Security setting can be found in TOOLS>>>MACRO>>>SECURITY

    D ;)


    :sailboat: [SIZE=1]Better a bad day on the water than a good day in the office[/SIZE]

  • Re: Macro To Show Messagebox On Open Doc


    Kurt - those certainly work with excel, but the question was with regard to word...just tried auto_open and that did not work - the actual event that fires on open is Document_Open

    D ;)


    :sailboat: [SIZE=1]Better a bad day on the water than a good day in the office[/SIZE]

  • Re: Macro To Show Messagebox On Open Doc


    No worries - slipped up that way a few times myself, thinking it was excel and it turned out to be access...


    but there are also forums for Word / SQL / Access etc.


    You can see which forum the post has been made in at the top of each thread, eg this one is in


    Excel Help/VBA Help: > Main Question Help Forums > Word Help

    D ;)


    :sailboat: [SIZE=1]Better a bad day on the water than a good day in the office[/SIZE]

  • Re: Macro To Show Messagebox On Open Doc


    Quote from DaveR (UK)

    Kurt - those certainly work with excel, but the question was with regard to word...just tried auto_open and that did not work - the actual event that fires on open is Document_Open


    Sub AutoOpen() is what you want in WORD.
    Sub Auto_Open() is what you want in EXCEL
    This is just an inconsistency (and frustrating) difference between VB code for Word and VB code for Excel.

    Code
    '-------- AUTOOPEN ---------------
    Sub AutoOpen 'runs when document is opened
    'This name "AutoOpen" is a Visual Basic reserved name for launching
    'code when a Word document is opened.
    'AutoOpen works in Word   'Auto_Open works in Excel
        MsgBox "Ensure that you get Manager authorization",vbOKOnly+vbInformation,"MyMacro" 
    End Sub
  • Re: Macro To Show Messagebox On Open Doc


    How many ways can you skin a cat ;)


    Just out of interest, what are the pros and cons of the two methods....AutoOpen and Document_Open :confused:

    D ;)


    :sailboat: [SIZE=1]Better a bad day on the water than a good day in the office[/SIZE]

  • Re: Macro To Show Messagebox On Open Doc


    Ahhh...thanks Dave :thanx: always handy to know...

    D ;)


    :sailboat: [SIZE=1]Better a bad day on the water than a good day in the office[/SIZE]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!