Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Location
    London
    Posts
    341

    Unanswered: code to trash my code?

    Hi.

    I don't actually know if this is even possible but i have a number of examples of my work that i want to make avaliable as part of an application to a specialist role but i want to protect my work from simple theft. At the moment i have little snippets of code outside of my master documents that say if the date is after x, then make read only, or hide buttons etc.

    In some instances i have an activation date and the code is effective in x amount of time.

    What I would like to do is to wipe as much code out as i can instead of all the above. Is this possible and how would I achieve this?
    Last edited by christyxo; 07-18-11 at 07:03.

  2. #2
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    Never mind, I've actually found how to do it. This works in EXCEL but I haven't attempted it in Access or any other MS application yet.

    • You need to set an reference to the VBA Extensibililty library.

    • You need to enable programmatic access to the VBA Project.

    This code deletes all VB code

    Code:
    Sub DeleteAllVBACode()
            Dim VBProj As VBIDE.VBProject
            Dim VBComp As VBIDE.VBComponent
            Dim CodeMod As VBIDE.CodeModule
            
            Set VBProj = ActiveWorkbook.VBProject
            
            For Each VBComp In VBProj.VBComponents
                If VBComp.Type = vbext_ct_Document Then
                    Set CodeMod = VBComp.CodeModule
                    With CodeMod
                        .DeleteLines 1, .CountOfLines
                    End With
                Else
                    VBProj.VBComponents.Remove VBComp
                End If
            Next VBComp
        End Sub
    This deletes a specific module, which is actually closer to what I wanted:

    Code:
        Sub DeleteModule()
            Dim VBProj As VBIDE.VBProject
            Dim VBComp As VBIDE.VBComponent
        
            Set VBProj = ActiveWorkbook.VBProject
            Set VBComp = VBProj.VBComponents("Module1")
            VBProj.VBComponents.Remove VBComp
        End Sub

Posting Permissions

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