+ Reply to Thread
Results 1 to 6 of 6

Deleting a 'workbook' macro

  1. #1
    Registered User
    Join Date
    05-16-2005
    Posts
    2

    Deleting a 'workbook' macro

    Good day all, I wonder if anyone has come across this before?

    I have a 'private sub' macro which runs when a template is opened. The utility of this is to assign an incremental Project ID to the template each time it is opened. Obviously, the template is then saved under a different name...as well as being saved as an .xls file.

    The problem: The private sub code is still there when the new named worksheet is opened and the increment still clicks up one number everytime the sheet is opened. I have been trying to write code to insert after the existing code in the .xlt file which will effectively delete the code once the template has assigned a number.

    I am afraid I have not been able to do this, so any help would be greatly appreciated.

    Thank you.

  2. #2
    Bob Phillips
    Guest

    Re: Deleting a 'workbook' macro

    Here is some code to delete the Workbook_Open code

    --
    HTH

    Bob Phillips

    "chiv" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Good day all, I wonder if anyone has come across this before?
    >
    > I have a 'private sub' macro which runs when a template is opened. The
    > utility of this is to assign an incremental Project ID to the template
    > each time it is opened. Obviously, the template is then saved under a
    > different name...as well as being saved as an .xls file.
    >
    > The problem: The private sub code is still there when the new named
    > worksheet is opened and the increment still clicks up one number
    > everytime the sheet is opened. I have been trying to write code to
    > insert after the existing code in the .xlt file which will effectively
    > delete the code once the template has assigned a number.
    >
    > I am afraid I have not been able to do this, so any help would be
    > greatly appreciated.
    >
    > Thank you.
    >
    >
    > --
    > chiv
    > ------------------------------------------------------------------------
    > chiv's Profile:

    http://www.excelforum.com/member.php...o&userid=23400
    > View this thread: http://www.excelforum.com/showthread...hreadid=373371
    >




  3. #3
    IC
    Guest

    Re: Deleting a 'workbook' macro

    Bob, there's no code in your post.

    Ian

    "Bob Phillips" <[email protected]> wrote in message
    news:%[email protected]...
    > Here is some code to delete the Workbook_Open code
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > "chiv" <[email protected]> wrote in message
    > news:[email protected]...
    >>
    >> Good day all, I wonder if anyone has come across this before?
    >>
    >> I have a 'private sub' macro which runs when a template is opened. The
    >> utility of this is to assign an incremental Project ID to the template
    >> each time it is opened. Obviously, the template is then saved under a
    >> different name...as well as being saved as an .xls file.
    >>
    >> The problem: The private sub code is still there when the new named
    >> worksheet is opened and the increment still clicks up one number
    >> everytime the sheet is opened. I have been trying to write code to
    >> insert after the existing code in the .xlt file which will effectively
    >> delete the code once the template has assigned a number.
    >>
    >> I am afraid I have not been able to do this, so any help would be
    >> greatly appreciated.
    >>
    >> Thank you.
    >>
    >>
    >> --
    >> chiv
    >> ------------------------------------------------------------------------
    >> chiv's Profile:

    > http://www.excelforum.com/member.php...o&userid=23400
    >> View this thread:
    >> http://www.excelforum.com/showthread...hreadid=373371
    >>

    >
    >




  4. #4
    Damien McBain
    Guest

    Re: Deleting a 'workbook' macro

    "chiv" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Good day all, I wonder if anyone has come across this before?
    >
    > I have a 'private sub' macro which runs when a template is opened. The
    > utility of this is to assign an incremental Project ID to the template
    > each time it is opened. Obviously, the template is then saved under a
    > different name...as well as being saved as an .xls file.
    >
    > The problem: The private sub code is still there when the new named
    > worksheet is opened and the increment still clicks up one number
    > everytime the sheet is opened. I have been trying to write code to
    > insert after the existing code in the .xlt file which will effectively
    > delete the code once the template has assigned a number.


    You could create the new workbook based on another template (xls or xlt)
    which has no VBA, save it with the filename you want and close the original
    workbook (with the code) all in one hit. So the original workbook would run
    the code then close and leave the new saved workbook active.



  5. #5
    Bob Phillips
    Guest

    Re: Deleting a 'workbook' macro

    Sorry Ian,

    Sub DeleteProcedure()
    Dim oVBMod As Object
    Dim iStart As Long
    Dim cLines As Long

    Set oVBMod =
    ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
    With oVBMod
    iStart = .ProcStartline("Workbook_Open", 0)
    cLines = .ProcCountLines("Workbook_Open", 0)
    .DeleteLines iStart, cLines
    End With

    End Sub


    --
    HTH

    Bob Phillips

    "IC" <[email protected]> wrote in message
    news:[email protected]...
    > Bob, there's no code in your post.
    >
    > Ian
    >
    > "Bob Phillips" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Here is some code to delete the Workbook_Open code
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > "chiv" <[email protected]> wrote in message
    > > news:[email protected]...
    > >>
    > >> Good day all, I wonder if anyone has come across this before?
    > >>
    > >> I have a 'private sub' macro which runs when a template is opened. The
    > >> utility of this is to assign an incremental Project ID to the template
    > >> each time it is opened. Obviously, the template is then saved under a
    > >> different name...as well as being saved as an .xls file.
    > >>
    > >> The problem: The private sub code is still there when the new named
    > >> worksheet is opened and the increment still clicks up one number
    > >> everytime the sheet is opened. I have been trying to write code to
    > >> insert after the existing code in the .xlt file which will effectively
    > >> delete the code once the template has assigned a number.
    > >>
    > >> I am afraid I have not been able to do this, so any help would be
    > >> greatly appreciated.
    > >>
    > >> Thank you.
    > >>
    > >>
    > >> --
    > >> chiv

    >
    >> ------------------------------------------------------------------------
    > >> chiv's Profile:

    > > http://www.excelforum.com/member.php...o&userid=23400
    > >> View this thread:
    > >> http://www.excelforum.com/showthread...hreadid=373371
    > >>

    > >
    > >

    >
    >




  6. #6
    IC
    Guest

    Re: Deleting a 'workbook' macro

    That's OK, Bob. It didn't really worry me but I thought I'd mention it for
    chiv's benefit.

    Ian

    "Bob Phillips" <[email protected]> wrote in message
    news:[email protected]...
    > Sorry Ian,
    >
    > Sub DeleteProcedure()
    > Dim oVBMod As Object
    > Dim iStart As Long
    > Dim cLines As Long
    >
    > Set oVBMod =
    > ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
    > With oVBMod
    > iStart = .ProcStartline("Workbook_Open", 0)
    > cLines = .ProcCountLines("Workbook_Open", 0)
    > .DeleteLines iStart, cLines
    > End With
    >
    > End Sub
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > "IC" <[email protected]> wrote in message
    > news:[email protected]...
    >> Bob, there's no code in your post.
    >>
    >> Ian
    >>
    >> "Bob Phillips" <[email protected]> wrote in message
    >> news:%[email protected]...
    >> > Here is some code to delete the Workbook_Open code
    >> >
    >> > --
    >> > HTH
    >> >
    >> > Bob Phillips
    >> >
    >> > "chiv" <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >>
    >> >> Good day all, I wonder if anyone has come across this before?
    >> >>
    >> >> I have a 'private sub' macro which runs when a template is opened.
    >> >> The
    >> >> utility of this is to assign an incremental Project ID to the template
    >> >> each time it is opened. Obviously, the template is then saved under a
    >> >> different name...as well as being saved as an .xls file.
    >> >>
    >> >> The problem: The private sub code is still there when the new named
    >> >> worksheet is opened and the increment still clicks up one number
    >> >> everytime the sheet is opened. I have been trying to write code to
    >> >> insert after the existing code in the .xlt file which will effectively
    >> >> delete the code once the template has assigned a number.
    >> >>
    >> >> I am afraid I have not been able to do this, so any help would be
    >> >> greatly appreciated.
    >> >>
    >> >> Thank you.
    >> >>
    >> >>
    >> >> --
    >> >> chiv

    >>
    >>> ------------------------------------------------------------------------
    >> >> chiv's Profile:
    >> > http://www.excelforum.com/member.php...o&userid=23400
    >> >> View this thread:
    >> >> http://www.excelforum.com/showthread...hreadid=373371
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >




+ 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