+ Reply to Thread
Results 1 to 3 of 3

Run a macro automatically on workbook open

  1. #1
    tweacle
    Guest

    Run a macro automatically on workbook open


    I have a workbook which is networked. Im trying to include a macro that
    will automatically run when the workbook is opened in read/write format
    but will not run when its read only.

    I understand macro's but aint got a clue on how to do this if it can be
    done. If it can could I poss have a idiot proof guide.

    Many Thanks


    --
    tweacle

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    sub workbook open

    at the top menu beside File, there is an excel symbol, right click on that icon and select view codes,
    Now at the drop down menu where it says general, drop down the menu to select -workbook
    go to the next drop down menu and select -open
    beginning and ending code appears
    copy and paste your macro between these two lines of code
    for example purposes
    copy and paste this code in between those two lines


    Dim Msg As String

    Msg = "This is Dave's great WorkBook!!"
    MsgBox Msg

    it will end up looking like this


    Private Sub Workbook_Open()
    Dim Msg As String

    Msg = "This is Dave's great WorkBook!!"
    MsgBox Msg
    End Sub
    Once you have that right then practise butting in the code from your macro
    After you find out where this code goes, check out Dave Peterson's reply
    Dave
    Last edited by davesexcel; 02-25-2006 at 02:46 PM.

  3. #3
    Dave Peterson
    Guest

    Re: Run a macro automatically on workbook open

    You could add a single line to the top of your procedure:


    Option Explicit
    Sub auto_open()
    If ThisWorkbook.ReadOnly Then Exit Sub

    'your normal code here
    End Sub

    (or workbook_open if you used that)

    tweacle wrote:
    >
    > I have a workbook which is networked. Im trying to include a macro that
    > will automatically run when the workbook is opened in read/write format
    > but will not run when its read only.
    >
    > I understand macro's but aint got a clue on how to do this if it can be
    > done. If it can could I poss have a idiot proof guide.
    >
    > Many Thanks
    >
    > --
    > tweacle


    --

    Dave Peterson

+ 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.6.0 RC 1