Results 1 to 9 of 9

Thread: Run a macro automatically everytime a file is opened

  1. #1
    Join Date
    Jul 2009
    Posts
    67

    Run a macro automatically everytime a file is opened

    Does anyone know how to get a macro to run automatically everytime a file is opened? Thanks

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Run a macro automatically everytime a file is opened

    It seems to me like you can try to use an Application Open Workbook Event. This is straight out of the help section.

    Private Sub App_WorkbookOpen(ByVal Wb As Workbook)

    ' your code here

    End Sub

  3. #3
    Join Date
    Dec 2006
    Posts
    489

    Re: Run a macro automatically everytime a file is opened

    For Project, look at the Project.Open event

  4. #4
    Join Date
    Jul 2009
    Posts
    67

    Re: Run a macro automatically everytime a file is opened

    So I have opened my project, then opened VBE, navigated to the 'ThisProject' file, selected 'Project' from the object pick list and selected 'Open' from the event pick list. Ive then entered my code:

    Private Sub Project_Open(ByVal pj As Project)
    My Macro code
    End sub

    Then saved and closed my file but the macro doesnt run when I open the mpp file. Anyone an idea what Ive missed?

  5. #5
    Join Date
    Dec 2006
    Posts
    489

    Re: Run a macro automatically everytime a file is opened

    Does any code run at all? Msgbox? What are your macro security settings? Project 2010 disables all macros except signed -- you'll need to drop the setting.

  6. #6
    Join Date
    Jul 2009
    Posts
    67

    Re: Run a macro automatically everytime a file is opened

    Thanks for your advice. If I 'Enable all macros' my Open event works fine but I am aware that this setting is potentially dangerous so my next question is; How do I digitally sign the macro so that it will run if I raise my macro setting?

  7. #7
    Join Date
    Dec 2006
    Posts
    489

    Re: Run a macro automatically everytime a file is opened

    You can create a self-signing certificate. See:
    http://office.microsoft.com/en-us/ex...010354312.aspx

    The other option is to get a signing authority but that is much longer and may cost money.

  8. #8
    Join Date
    Jul 2009
    Posts
    67

    Re: Run a macro automatically everytime a file is opened

    I have created a self-signing certificate and all works fine. Thanks for your help.

  9. #9
    Join Date
    Dec 2006
    Posts
    489

    Re: Run a macro automatically everytime a file is opened

    You are welcome. Glad to know the self-signed certificate works.

Similar Threads

  1. Replies: 6
    Last Post: 09-03-2011, 10:35 AM
  2. Replies: 3
    Last Post: 10-11-2009, 09:37 PM
  3. Replies: 2
    Last Post: 29-11-2008, 08:18 AM
  4. Replies: 4
    Last Post: 20-02-2008, 11:04 AM

Tags for this Thread

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
  •  
Page generated in 1,713,579,585.07361 seconds with 17 queries