+ Reply to Thread
Results 1 to 4 of 4

How to Remove Workbook_Open macro?

  1. #1
    Registered User
    Join Date
    12-03-2003
    Location
    UK
    Posts
    6

    How to Remove Workbook_Open macro?

    I have a Workbook_Open macro which is only required when the document is opened for the first time by a user. I want to have it remove itself after running. I suspect the answer lies in removing a VBComponent but I don't know how to tackle this.

    Can anyone help? Point me in the right direction?

    Thanks.

  2. #2
    Bob Phillips
    Guest

    Re: How to Remove Workbook_Open macro?

    '-----------------------------------------------------------------
    Private Sub Workbook_Open()
    '-----------------------------------------------------------------

    MsgBox "This procedure runs once only"

    Dim oCodeModule As Object
    Dim iStart As Long
    Dim cLines As Long

    Set oCodeModule =
    ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
    With oCodeModule
    iStart = .ProcStartLine("Workbook_Open", 0)
    cLines = .ProcCountLines("Workbook_Open", 0)
    .DeleteLines iStart, cLines
    On Error GoTo 0
    Exit Sub
    End With


    End Sub

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "ANDYGM" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I have a Workbook_Open macro which is only required when the document is
    > opened for the first time by a user. I want to have it remove itself
    > after running. I suspect the answer lies in removing a VBComponent but
    > I don't know how to tackle this.
    >
    > Can anyone help? Point me in the right direction?
    >
    > Thanks.
    >
    >
    > --
    > ANDYGM
    > ------------------------------------------------------------------------
    > ANDYGM's Profile:

    http://www.excelforum.com/member.php...fo&userid=3452
    > View this thread: http://www.excelforum.com/showthread...hreadid=532200
    >




  3. #3
    Robin Hammond
    Guest

    Re: How to Remove Workbook_Open macro?

    Rather than writing complex code to edit code modules, why not just save a
    registry value the first time the macro is run successfully, and have the
    macro check for this variable when the workbook is opened.

    Robin Hammond
    www.enhanceddatasystems.com

    "ANDYGM" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I have a Workbook_Open macro which is only required when the document is
    > opened for the first time by a user. I want to have it remove itself
    > after running. I suspect the answer lies in removing a VBComponent but
    > I don't know how to tackle this.
    >
    > Can anyone help? Point me in the right direction?
    >
    > Thanks.
    >
    >
    > --
    > ANDYGM
    > ------------------------------------------------------------------------
    > ANDYGM's Profile:
    > http://www.excelforum.com/member.php...fo&userid=3452
    > View this thread: http://www.excelforum.com/showthread...hreadid=532200
    >




  4. #4
    Registered User
    Join Date
    12-03-2003
    Location
    UK
    Posts
    6
    Great! I used the code and it worked perfectly. Thanks.

+ 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