T
Torbjörn Steijer
Hi,
I picked the code below from a very good site (can't find it again). For
those who have higher version than 9.0 this doesn't work. Is there any other
way to write to code so that it adds the reference depending on what version
you have?
If anybody know where I might have picked up the code, please let me know.
Best regards
Torbjörn
'All this code only works if Excel has a reference to the Outlook library
'the sub below ensures we do
Public Sub CheckReferences()
Dim ref As Object
Static blnRefFound As Boolean
If blnRefFound = True Then Exit Sub
'do we have a reference already? if so, exit
For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "Outlook" Then
blnRefFound = True
Exit Sub
End If
Next ref
'no reference? add it
If blnRefFound = False Then
'if you get an error below, the Outlook library is somewhere else. Search
for msoutl9.olb on your C drive, and
'when you find it, change the pathname on the next line and try again
Application.VBE.ActiveVBProject.References.AddFromFile
"C:\Program\Microsoft Office\Office\msoutl9.olb"
End If
End Sub
I picked the code below from a very good site (can't find it again). For
those who have higher version than 9.0 this doesn't work. Is there any other
way to write to code so that it adds the reference depending on what version
you have?
If anybody know where I might have picked up the code, please let me know.
Best regards
Torbjörn
'All this code only works if Excel has a reference to the Outlook library
'the sub below ensures we do
Public Sub CheckReferences()
Dim ref As Object
Static blnRefFound As Boolean
If blnRefFound = True Then Exit Sub
'do we have a reference already? if so, exit
For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "Outlook" Then
blnRefFound = True
Exit Sub
End If
Next ref
'no reference? add it
If blnRefFound = False Then
'if you get an error below, the Outlook library is somewhere else. Search
for msoutl9.olb on your C drive, and
'when you find it, change the pathname on the next line and try again
Application.VBE.ActiveVBProject.References.AddFromFile
"C:\Program\Microsoft Office\Office\msoutl9.olb"
End If
End Sub