If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > code to trash my code?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-11, 14:05
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
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 06:03.
Reply With Quote
  #2 (permalink)  
Old 07-18-11, 06:02
christyxo christyxo is offline
Registered User
 
Join Date: Oct 2003
Location: London
Posts: 291
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On