+ Reply to Thread
Results 1 to 5 of 5

Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Model

  1. #1
    Registered User
    Join Date
    05-30-2014
    Posts
    2

    Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Model

    Is this possible?

    I need a macro to either delete itself after running, delete another macro after it has run (either way), or simply overwrite itself (or another macro). Basically just need to hide a macro after a user runs it. I have found multiple solutions for this and have tested them. They work, IF you enable "Trust Access to VBA Project Object Model" in the Word options.

    Thoughts?

    I have tried multiple similar versions of this but all require the option to be enabled:

    Please Login or Register  to view this content.
    Thoughts? Thanks!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,971

    Re: Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Mo

    You cannot delete or modify VBA code without trusting access. That's why that setting is there.

    You can use some custom document property to disable the macro if it has been run already - check for a specific value, exit the macro if it does match, or run the macro and then set the property to the value that disables. If you want to delete all the VBA then a macro that saves the file as a docx instead of a docm might work....
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    05-30-2014
    Posts
    2

    Re: Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Mo

    Hi, Bernie. Thanks for the quick response!

    I'm sorry, but I do not fully understand what you mentioned. I am quite new to the world of Office macros and VBA. It sounded like maybe a macro could be checked and then changed?

    Basically, this is the code/concept that is in place. I simply want to hide/change the code in MacroA. Is there anyway to do that (I'm fine if I can't delete the macro as a whole)? Thanks!

    Please Login or Register  to view this content.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Mo

    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,971

    Re: Macro to delete itself (or other macro) without enabling Trust Access to VBA Object Mo

    Create a custom property named 'test' and set its type to text. Then change Macro A to this - after testing, you can remove the msgbox lines....

    Sub MacroA()
    MsgBox "Hello from Macro A"

    If ThisDocument.CustomDocumentProperties("test").Value = "Done" Then
    MsgBox "I already did stuff, so I will not do it again"
    Else
    MsgBox "I am going to do stuff now:"
    ThisDocument.CustomDocumentProperties("test").Value = "Done"
    '<do stuff>
    End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is it a BAD idea to enable "Trust access to the VBA project object model"
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-23-2015, 12:26 PM
  2. Replies: 6
    Last Post: 07-30-2013, 11:48 AM
  3. Macro / function to delete rows in Access
    By otterlygood in forum Excel General
    Replies: 0
    Last Post: 10-19-2008, 11:21 AM
  4. Macro/Security/Trust Access...
    By Paige in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2007, 05:52 AM
  5. want to access xml from excel object model
    By B Deepak in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-28-2005, 08:10 AM

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