+ Reply to Thread
Results 1 to 3 of 3

Adding library references with code -> error 1004

  1. #1
    Registered User
    Join Date
    02-12-2008
    Posts
    3

    Adding library references with code -> error 1004

    Hi,

    I have been trying to add a few reference libraries in my vba project. It works fine on my computer but I get this error message when I run it on someone else's computer:

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


    The code that I used is:
    ThisWorkBook.VBProject.References.AddFromFile ("C:\Program Files\Common Files\System\ADO\msado15.dll")

    I know that I can avoid this error by going into Tools-> Macro -> Security and check the box that says trust VBE project (or something like that). However, I'd like to add the reference library without having the user to do that.

    I also tried to use late binding but since I was intending to use late binding rather than adding a SAS reference library, some of the functions seems to not work...

    Anyone have any thoughts on how I can solve this problem?

    Thanks a lot for your time.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon cyc1120

    ...and welcome to the forum!!

    Quote Originally Posted by cyc1120
    I know that I can avoid this error by going into Tools-> Macro -> Security and check the box that says trust VBE project (or something like that). However, I'd like to add the reference library without having the user to do that.
    You can't. It's a security feature to stop malicious code writers from completely FUBARing a users machine without the user having any control in the matter.

    You can get around it by going to Tools > Macro > Security, Trusted Publishers and ticking the box marked Trust Access to Visual Basic Project.

    Best you can do is have your code to check if this is ticked, and if not, flash up a message to the user telling them what to do. That's what I've had to do in my apps.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    02-12-2008
    Posts
    3
    Thanks a lot for the quick response. It makes sense to me now...

+ 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