Consulting

Results 1 to 6 of 6

Thread: Solved: Trust Access to VB Project

  1. #1

    Solved: Trust Access to VB Project

    I have written code that uses some of the VB libraries but it requires that the user all access to the VB Project libraries.

    To turn this on, the user must go the the Security dialog box and the Trusted Publishers tab and check the box next to the "Trust access to Visual Basic Project".

    For security purposes, I do not believe that this can be turned on programatically.

    But, I would like code to check to see if it is checked. If it is NOT checked, it will open the security dialog box to the trusted publishers tab after telling the user they need to check the box.

    If the user attempts to run the code they get the error, "Run-time error '1004'. Programmatic access to Visual Basic Project is not trusted.

    How does one go about writing the code for this?
    Last edited by MrRhodes2004; 08-31-2006 at 08:46 AM.

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    MrRhodes,

    I do not have xl2002 or 2003, so I can't say for sure this will work, but I do know when this error appears for others. Perhaps you can use a function like:[vba]Function IsVBATrusted() As Boolean
    Dim VBC As Object
    Application.DisplayAlerts = False
    On Error Resume Next
    Set VBC = ThisWorkbook.VBProject.VBComponents.Item(1)
    On Error GoTo 0
    Application.DisplayAlerts = True
    IsVBATrusted = Not VBC Is Nothing
    End Function[/vba]
    I am not aware of any way to get that dialog to pop-up, though you may want to take a look at the Application.Dialogs collection, it may be in there for your version.

    As to your question about what is/isn't possible in VBA, I would like to point you to http://www.google.com


    Matt

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Works fine in XP.

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi there,

    There are ways, but they won't be posted to an open board like this. That would be like throwing candy out on the streets for hackers and telling them to come and get it; it'd only be a matter of time before everybody knew how to hack all projects! There would be pandemonium!!

    Anyway, I was in the middle of making a function quite like Matt's to test this property, but it's about the same anyway.

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Works fine in 2003 as well.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [VBA]Private Sub Workbook_Open()
    Call AddRefsIfAccessAllowed
    End Sub


    Private Sub AddRefsIfAccessAllowed()

    Dim Response As VbMsgBoxResult

    'Test to ensure access is allowed
    If Application.Version > 9 Then
    Dim VisualBasicProject As Object
    On Error Resume Next
    Set VisualBasicProject = ActiveWorkbook.VBproject
    If Not Err.Number = 0 Then
    Response = Msgbox("Your current security settings do not allow the code in this workbook " & vbNewLine & _
    " to work as designed and you will get some error messages." & vbNewLine & vbNewLine & _
    "To allow the code to function correctly and without errors you need" & vbNewLine & _
    " to change your security setting as follows:" & vbNewLine & vbNewLine & _
    " 1. Select Tools - Macro - Security to show the security dialog" & vbNewLine & _
    " 2. Click the 'Trusted Sources' tab" & vbNewLine & _
    " 3. Place a checkmark next to 'Trust Access to Visual Basic Project'" & vbNewLine & _
    " 4. Save - then Close and re-open the workbook" & vbNewLine & vbNewLine & _
    "Do you want the security dialog shown now?", vbYesNoCancel + vbCritical)
    If Response = vbYes Then Application.CommandBars("Macro").Controls("Security...").Execute
    Exit Sub
    End If
    End If

    End Sub[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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