Macro to delete a macro?
Find bottlenecks in your Excel workbooks
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Macro to delete a macro?

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Hi again,

    I have a macro which I want to run one time, then delete it with code.

    I was thinking have 2 macros, then when the one i want to delete runs, at the end ill add "Call deletemacro" which will call the 2nd macro to delete the first.

    Does anyone have the code to delete a module of code from within vb?

    Thanks

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Take a look at Chip's page here:
    http://www.cpearson.com/excel/vbe.htm
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi al,
    Thanks for the link, i added the reference and tried this code:
    Sub Delete_Save()
    Dim VBComp As VBComponent
    Set VBComp = ThisWorkbook.VBProject.VBComponents("SaveMacro")
    ThisWorkbook.VBProject.VBComponents.Remove VBComp
    End Sub

    but im getting the error "Programmic access to Visual Basic Project is not trusted".

    is there a way to get around this?

    thanks

  4. #4
    . MrExcel's Avatar
    Join Date
    Feb 2002
    Location
    Merritt Island Florida
    Posts
    858
    Post Thanks / Like
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Yes. In tools > Macro > security, you can change this. Go to Trusted Sources tab and check the box for Trust Access to Visual Basic Project.
    View a collection of recent Excel articles in the Excel Daily News

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com