Deleting code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am reposting the same concern with a try to explain it in better way

I have a template which i need to distribute to unknown number of audiance. I need to delete all the code (forms, modules etc) after my output is done (Main Reson : Size, and code + data security). I am using the below code to do that but If "Programmatic access to Visual Basic Project is not trusted" is not checked manually, i get the following error : Programmatic access to Visual Basic Project is not trusted, "Runtime error 1004

Is there anyway that I can set the option under: "Tools, Macro, Security...Trust access to Visual Basic Project" through my VBA code.

Sub DeleteALLVBA(
Dim VBComp As VBIDE.VBComponen
Dim VBComps As VBIDE.VBComponent

Set VBComps = ActiveWorkbook.VBProject.VBComponent

For Each VBComp In VBComp
Select Case VBComp.Typ
Case vbext_ct_StdModule, vbext_ct_MSForm, vbext_ct_ClassModul
VBComps.Remove VBCom
Case Els
With VBComp.CodeModul
.DeleteLines 1, .CountOfLine
End Wit
End Selec
Next VBCom
End Su
 
There wouldn't be any reason to have it as a form of protection if there
was.

--
Regards,
Tom Ogilvy

Ajit said:
I am reposting the same concern with a try to explain it in better way.

I have a template which i need to distribute to unknown number of
audiance. I need to delete all the code (forms, modules etc) after my output
is done (Main Reson : Size, and code + data security). I am using the below
code to do that but If "Programmatic access to Visual Basic Project is not
trusted" is not checked manually, i get the following error : Programmatic
access to Visual Basic Project is not trusted, "Runtime error 1004"
Is there anyway that I can set the option under: "Tools, Macro,
Security...Trust access to Visual Basic Project" through my VBA code.
 
But size could be a big concern. Do you think i should follow the logic for deleting the code and modules or would you suggest something else
 
Hi Ajit,
But size could be a big concern. Do you think i should follow the
logic for deleting the code and modules or would you suggest
something else

I would suggest something else. Instead of housing code in your template,
put all the code in an add-in or other "master" workbook. The master, when
a button or menu item is clicked, will create a new workbook based on the
template, manipulate the workbook as needed, and do a SaveAs. That way, you
don't have to worry about having to strip code out of the template.

Another benefit to this model is that you can change the code without (in
most cases) modifying the template. And vice versa.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Back
Top