+ Reply to Thread
Results 1 to 13 of 13

Excel 2007: error '1004' Programmatic access is NOT trusted

  1. #1
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Excel 2007: error '1004' Programmatic access is NOT trusted

    I'm running some code on XP Excel 2007 and receive the error below

    Runtime error '1004'
    Programmatic access to Visual Basic Project is not trusted.


    I found a solution to this issue - used it and it DOES solve the issue - no more error and my program executes correctly on the XP Excel 2007 system where it previously failed
    (NOTE: This same code works correctly on my XP Excel 2000 system)
    ------------------------------------------------------------------------------------------------------------
    From the MS KB Article #812969

    http://support.microsoft.com/kb/813969

    States:
    When you run code that uses the Microsoft Visual Basic for Applications Extensibility 5.3

    Library, you may receive the following error message:

    Run-time error '1004': Programmatic access to the Visual Basic Project is not trusted

    Solution:
    Excel 2007
    Click the Microsoft Office Button, and then click Excel Options.
    Click Trust Center.
    Click Trust Center Settings.
    Click Macro Settings.
    Click to select the Trust access to the VBA project object model check box.
    Click OK to close the Excel Options dialog box.

    Excel 2003
    On the Tools menu, point to Macro, and then click Security.
    In the Security dialog box, click the Trusted Sources tab.
    Select the Trust access to Visual Basic Project check box.
    Click OK.
    ------------------------------------------------------------------------------------------------------------

    Is there a way for me to turn this setting ON programatically when I need it?

    Thanks,


    BTW: A better solution would be - get the setting that the user has, set it to what I need to not CRASH, then return back to the USERS setting after I'm done.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    See http://www.experts-exchange.com/Soft..._21730594.html

    I would be very reluctant to change a registry setting on someone else's computer.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Thanks for the response.....

    1). Though I can't see the answer (the thread) w/o being a "user" on that forum
    I guess I could get a 30 day trial to view the answer, but I'm NOT giving my credit card and picking a plan for the answer to ONE of my questions.

    2). and I did say the following in my original post...
    BTW: A better solution would be - get the setting that the user has, set it to what I need to not CRASH, then return back to the USERS setting after I'm done.
    so I would change the setting to get the functionality to work, then change it back

    3). The other solution would be for me to tell the user to go change their setting for this functionality to work.... Not an elegant solution for the user, if they can actually find their way there and get the setting correct.

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Have I missed something? You don't actually say what line of code is being executed when this error occurs.


    click on the * Add Reputation if this was useful or entertaining.

  5. #5
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Nope - you didn't miss it and it really doesn't matter. IMHO

    I get the error on Excel 07 and not Excel 2000, Hence it points the issue to an Excel 07 specific area (or feature) which is described in the initial post.

    The fix is also evident and works, just manual. I'd just like to make this easy on the user vs telling them "In order to make my program that works on your machine actually work... Follow these steps or Excel will CRASH". Not very user friendly......

  6. #6
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Anyone else - any way to perform those setting programatically????

  7. #7
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    I haven't spent much time on it but I couldn't find a simple way.

    If I needed to find a solution, and depending on your deployment model, I would investigate using a startup script (ie runs before Excel and launches excel) to make the change and another run on workbookClose to set it back.

    This is a technique I have used for other issues but I haven't specifically done it for this issue.

    Regards

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Google 'AccessVBOM' which is the registry key you need to change. I don't know whether UAC in Vista and 7 will prevent the changes being made, but I suspect that in some offices users might be prevented from altering the security settings.
    The usual method is to pop up a message (you can use a hidden sheet with instructions and screen prints) telling the user how to do it.

    PS Depending on what your code is doing, you may find that certain anti-virus apps really dislike code that uses the VBA Extensibility stuff.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Thanks for the recent replies - tonyh & rimperstomper, I'll try the suggestions.

    And look for additional ways to make this work....

    Thanks,

  10. #10
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    The reason I'm using "Microsoft Visual Basic for Applications Extensibility 5.3" and thus getting errors on Excel 2003 & 2007 is because I'm retrieving, removing and copying module names from an Excel file. I update from a source file into a destination file for upgrades/updates....

    Is there anyway to do these operations without the VBIDE.VBProject reference and using this extension?

    If not, I'll have to resort to the following....... I'll detect the setting (and the impending error) using the suggestions above and some "ACCESSVBOM" code I found, and either popup instructions or redirect them to the instructions on my website. Allow the user to make the registry change to successfully update/upgrade their product.....


    Thanks,

  11. #11
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    Obviously I don't really know the complete scenario but if you do have to update the code sections then you do need the VBIDE. Unless you go down to direct updates of the files.

    What I wonder is why you have to do so. I would look to seperating out the changable code into an xla and keeping the calls to the xla in a form that would be unchanged. Then you just need to deliver a new xla.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    You don't need to set the reference (you can late bind) but you do need the Trusted Access.

  13. #13
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Re: Excel 2007: error '1004' Programmatic access is NOT trusted

    I decided to do direct updates of the files vs updating the modules within the file and using the "Microsoft Visual Basic for Applications Extensibility 5.3" and therefore getting the "Trusted App" issue on Excel 03/07.

    I could have detected the setting that would cause the issue, and either explain what needed to be performed to avoid the issue or pointed the user to a web site that explained what to do. This is a hassle that I just didn't want the user to go through....

    Thanks for your help & suggestions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1