Programmatically allowing access to Visual Basic Project

iangorm

New Member
Joined
Sep 9, 2002
Messages
8
Hi,

I am developing an application where I programmatically remove some macros from workbook A, using a macro in workbook B prior to saving workbook A.

In Excel 2003 it seems that the default security level for macros is set to NOT trust "access to Visual Basic Project" programmatically. This stops my program to remove the macros in workbook A from running.

Does anyone know of some VBA code that I can run from workbook B to change the check box in macro security to allow programmatic "access to Visual BAsic Project"?

Once the macros are removed from workbook A then I want to return the Excel security setting to NOT trust "access to Visual Basic Project" programmatically.

I know how to do this manually, but would like to maximise security by only lowering security for the time required.

Hoping someone can help.

All the Best,

Ian
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The only way I can think of to do this at the moment is with SendKeys.

I tried:

Code:
    SendKeys "%toisss%st%v", True
    Application.Wait Now + TimeValue("00:00:01")
    SendKeys "{TAB}~{ESC}{ESC}{ESC}", True

but I still end up back at the Trusted sources tab.
 
Upvote 0
You can't lower the security setting programtically.
This best way IMHO is as TazGuy & Tom have alluded to is to allow the users to set this for you ..... eg

Rich (BB code):
Option Explicit

http://xcelfiles.homestead.com/Security.html

Sub CheckSecurity()
Dim Q As Integer

TryNow:
'// Check security settings 1st!
If Not SecuritySet(ThisWorkbook) Then
    Q = MsgBox("These routines access your VBA modules" & vbCrLf & vbCrLf & _
        "Please set your security to [Trust access to Visual basic Project]." & vbCrLf & vbCrLf & _
        "Select [Security] > " & vbCrLf & vbTab & "Tab [Trusted Publishers] > " & _
        vbTab & vbCrLf & vbTab & vbTab & "Click [Trust access to Visual basic Project]" & vbCrLf & vbCrLf & _
        "You will be taken to these settings after clicking OK" & vbCrLf & _
        "Click cancel to skip setting this.", vbCritical + vbOKCancel, "Security settings")
    If Q = vbOK Then
        With Application
            .SendKeys "t"
            .CommandBars.FindControl(ID:=3627).Execute
        End With
        GoTo TryNow
    End If
End If

End Sub

Function SecuritySet(WBk As Workbook) As Boolean
Dim objVbaProj As Object

    '// Check Security
    On Error Resume Next
    '// Note LateBinding so NO reference to Extensibilty Lib Required
    Set objVbaProj = WBk.VBProject
    
    '// Check Version
    If CDbl(Val(Application.Version)) > 9 Then
        SecuritySet = Not CBool(Err.Number)
    Else
        SecuritySet = True
    End If
    On Error GoTo 0

End Function
 
Upvote 0

Forum statistics

Threads
1,206,826
Messages
6,075,096
Members
446,120
Latest member
Heremion

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top