1

I'm trying to write a macro to add a reference to the Skype4COM.dll library, but I'm not getting far.

First I tried this code:

ThisWorkbook.VBProject.References.AddFromFile ("C:\Program Files(x86)\Common Files\Skype\Skype4COM.dll")

But it says that the method is not trustful.

then I got this code from: How to add a reference programmatically But I can't reference to VBIDE.VBE

Finally I tried to use the GUID thing, so I got the code from this http://www.vbaexpress.com/kb/getarticle.php?kb_id=267

And to find the GUID Code I used this

Option Explicit 

Sub ListReferencePaths() 

On Error Resume Next 
Dim i As Long 
With ThisWorkbook.Sheets(1) 
    .Cells.Clear 
    .Range("A1") = "Reference name" 
    .Range("B1") = "Full path to reference" 
    .Range("C1") = "Reference GUID" 
End With 
For i = 1 To ThisWorkbook.VBProject.References.Count 
    With ThisWorkbook.VBProject.References(i) 
        ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Offset(1, 0) = .Name 
        ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Offset(0, 1) = .FullPath 
        ThisWorkbook.Sheets(1).Range("A65536").End(xlUp).Offset(0, 2) = .GUID 
    End With 
Next i 
On Error Goto 0 
End Sub 

But I returns nothings (I can't use the thisworkbook.vbproject.refereces), Anyone can help me? If you'd like I can paste all the codes here.

Thank you

Community
  • 1
  • 1
Fabio Rebelo
  • 109
  • 2
  • 5
  • 13
  • does it work when you add it manually using the browse button? –  Sep 23 '13 at 15:32
  • 2
    If you can't reference VBE and you can't use the VBProject objects, you can't do it. VBE is what you are adding the references to. The VBProject objects are the interface to VBE through which you add the references. You aren't clear on why you can't use the VBProject objects or reference VBE. Is it because you don't have the security option set? [See here](http://stackoverflow.com/questions/5300770/how-to-check-from-net-code-whether-trust-access-to-the-vba-project-object-mode). Or is it that you aren't allowed to change that setting in the environment you are working in? – AndASM Sep 23 '13 at 15:36
  • mehow: Yes I can do it manually, by clicking tools, references, and them ticking the skype reference. – Fabio Rebelo Sep 23 '13 at 16:23
  • AndASM: I check the File>Options>Trust Center>Trust Center Settings>Macro Settings>Trust access to the VBA project object model, and it's working now, but I'm wondering, is there a way to check it via macro?! – Fabio Rebelo Sep 23 '13 at 16:30

0 Answers0