View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steph[_6_] Steph[_6_] is offline
external usenet poster
 
Posts: 92
Default Can code delete code

Thanks for all your help Chip. Much appreciated!!

"Chip Pearson" wrote in message
...
Steph,

The following code will test whether access to the VBProject is
enabled.

Dim Ref As Object
On Error Resume Next
Set Ref = ThisWorkbook.VBProject.References("Excel")
If Ref Is Nothing Then
Debug.Print "No trust"
Else
Debug.Print "trust"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steph" wrote in message
...
Chip,
One more question - can I test prior to runtime whether or not
the trusted
source box is checked, and if not prompt a msgbox?

"Chip Pearson" wrote in message
...
Steph,

You can get around the requirement that the Extensibility
library
be set. Declare the VBIDE variables As Object, and replace the
constants that begin with vbext_ with their actual numeric
values.

You can programmatically add a reference to the Extensibility
library with code like


Dim Ref As Object
On Error Resume Next
Err.Clear
Set Ref = ActiveWorkbook.VBProject.References("VBIDE")
If Ref Is Nothing Then
ActiveWorkbook.VBProject.References.AddFromGuid _
GUID:="{0002E157-0000-0000-C000-000000000046}", _
Major:=5, Minor:=3
End If


You cannot programmatically change the "Trust Access To
VBProject" setting. This must be done manually.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steph" wrote in message
...
Can I ask a follow-up question? From Chip's site, I learned
that the VBA
Extensibility library reference must be set, along with the
Trust access to
VB project check box. Can these be "set" programatically?

"Steph" wrote in message
...
Thanks guys!

"Steph" wrote in message
...
Hello, can any of the following be done, and if so, can
you
please give
an
example of syntax? Thanks!

1. Can code delete an open event procedure?
2. Can code delete an entire module?
3. Can code delete specific lines within a module?
4. CAn code delete an entire sub() within a module?

Thanks again!