+ Reply to Thread
Results 1 to 6 of 6

How To Delete an Excel Macro by Using Automation

  1. #1
    ScottG
    Guest

    How To Delete an Excel Macro by Using Automation

    We automate Excel (v10) to generate a bunch a workbooks which populate and
    format themselves with an imbedded macro. Is there any way to
    programmatically delete the macro before distributing the documents?

  2. #2
    Bob Phillips
    Guest

    Re: How To Delete an Excel Macro by Using Automation

    Here is an example to delete a procedure


    Const vbext_pk_Proc = 0


    '----------------------------------------------------------------
    Sub DeleteProcedure()
    '----------------------------------------------------------------
    Dim oCodeModule As Object
    Dim iStart As Long
    Dim cLines As Long

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

    dp_err:
    If Err.Number = 35 Then
    MsgBox "Procedure does not exist"
    End If
    End Sub



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "ScottG" <[email protected]> wrote in message
    news:[email protected]...
    > We automate Excel (v10) to generate a bunch a workbooks which populate and
    > format themselves with an imbedded macro. Is there any way to
    > programmatically delete the macro before distributing the documents?




  3. #3
    Tom Ogilvy
    Guest

    Re: How To Delete an Excel Macro by Using Automation

    http://www.cpearson.com/excel/vbe.htm

    should give you a start.

    --
    Regards,
    Tom Ogilvy

    "ScottG" <[email protected]> wrote in message
    news:[email protected]...
    > We automate Excel (v10) to generate a bunch a workbooks which populate and
    > format themselves with an imbedded macro. Is there any way to
    > programmatically delete the macro before distributing the documents?




  4. #4
    ScottG
    Guest

    Re: How To Delete an Excel Macro by Using Automation

    Thanks, that worked perfectly.

    Scott

    "Bob Phillips" wrote:

    > Here is an example to delete a procedure
    >
    >
    > Const vbext_pk_Proc = 0
    >
    >
    > '----------------------------------------------------------------
    > Sub DeleteProcedure()
    > '----------------------------------------------------------------
    > Dim oCodeModule As Object
    > Dim iStart As Long
    > Dim cLines As Long
    >
    > Set oCodeModule =
    > ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
    > With oCodeModule
    > On Error GoTo dp_err:
    > iStart = .ProcStartLine("myProc", vbext_pk_Proc)
    > cLines = .ProcCountLines("myProc", vbext_pk_Proc)
    > .DeleteLines iStart, cLines
    > On Error GoTo 0
    > Exit Sub
    > End With
    >
    > dp_err:
    > If Err.Number = 35 Then
    > MsgBox "Procedure does not exist"
    > End If
    > End Sub
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "ScottG" <[email protected]> wrote in message
    > news:[email protected]...
    > > We automate Excel (v10) to generate a bunch a workbooks which populate and
    > > format themselves with an imbedded macro. Is there any way to
    > > programmatically delete the macro before distributing the documents?

    >
    >
    >


  5. #5
    keepITcool
    Guest

    Re: How To Delete an Excel Macro by Using Automation


    caveat:
    when users run those macros they must have a security setting.
    "Allow access to Visual Basic Project"

    if not your code will fail.

    in xl2002 it could be changed via Macro Options by user..
    in xl2003 this setting can only be changed with admin priviliges
    via registry... in HKLM


    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    ScottG wrote :

    > Thanks, that worked perfectly.
    >
    > Scott
    >
    > "Bob Phillips" wrote:
    >
    > > Here is an example to delete a procedure
    > >
    > >
    > > Const vbext_pk_Proc = 0
    > >
    > >
    > > '----------------------------------------------------------------
    > > Sub DeleteProcedure()
    > > '----------------------------------------------------------------
    > > Dim oCodeModule As Object
    > > Dim iStart As Long
    > > Dim cLines As Long
    > >
    > > Set oCodeModule =
    > > ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
    > > With oCodeModule
    > > On Error GoTo dp_err:
    > > iStart = .ProcStartLine("myProc", vbext_pk_Proc)
    > > cLines = .ProcCountLines("myProc", vbext_pk_Proc)
    > > .DeleteLines iStart, cLines
    > > On Error GoTo 0
    > > Exit Sub
    > > End With
    > >
    > > dp_err:
    > > If Err.Number = 35 Then
    > > MsgBox "Procedure does not exist"
    > > End If
    > > End Sub
    > >
    > >
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "ScottG" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > We automate Excel (v10) to generate a bunch a workbooks which
    > > > populate and format themselves with an imbedded macro. Is there
    > > > any way to programmatically delete the macro before distributing
    > > > the documents?

    > >
    > >
    > >


  6. #6
    Halray
    Guest

    Re: How To Delete an Excel Macro by Using Automation

    Bob,

    I tied the code, but I must be doing soemthing wrong because I get the
    following error:

    Method 'VBProject' of object '_Workbook' failed.


    Can you help me with this? Many Thanks!

    Ray Collins


    --
    Ray


    "Bob Phillips" wrote:

    > Here is an example to delete a procedure
    >
    >
    > Const vbext_pk_Proc = 0
    >
    >
    > '----------------------------------------------------------------
    > Sub DeleteProcedure()
    > '----------------------------------------------------------------
    > Dim oCodeModule As Object
    > Dim iStart As Long
    > Dim cLines As Long
    >
    > Set oCodeModule =
    > ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
    > With oCodeModule
    > On Error GoTo dp_err:
    > iStart = .ProcStartLine("myProc", vbext_pk_Proc)
    > cLines = .ProcCountLines("myProc", vbext_pk_Proc)
    > .DeleteLines iStart, cLines
    > On Error GoTo 0
    > Exit Sub
    > End With
    >
    > dp_err:
    > If Err.Number = 35 Then
    > MsgBox "Procedure does not exist"
    > End If
    > End Sub
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "ScottG" <[email protected]> wrote in message
    > news:[email protected]...
    > > We automate Excel (v10) to generate a bunch a workbooks which populate and
    > > format themselves with an imbedded macro. Is there any way to
    > > programmatically delete the macro before distributing the documents?

    >
    >
    >


+ 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