J
Joel Wiseheart
I tried to create a function to add References through
code. It almost works, but crashes occasionally when
comparing path names, to make sure the reference doesn't
already exist.
The reason is that Sometimes ref.FullPath
returns 'C:\Program Files\Common Files\...' and other
times it returns 'C:\Progra~1\Common~1\...', and it
doesn't see these two strings as being equal. I put >>>>
and <<<< around the line where this problem is occuring.
Here's the code, passing 'cdo.dll' and 'BarTend.exe' as
reference variables:
Public Function AddReference(strRefNameAndExt As String,
Optional strRefPath As String)
'Purpose: Adds reference for new installations.
'Variables: strRefNameAndExt = The name and file extension
of the reference being added.
' strRefPath = Path name to begin
search. "c:\Program Files" is used by default,
' unless otherwise specified.
'On Error GoTo Error_AddReference
Dim strReturnedPath As String
Dim ref As Reference
With Application.FileSearch 'Search for
reference called by function.
.NewSearch
If strRefPath = "" Then
.LookIn = "C:\Program Files"
Else
.LookIn = "strRefPath"
End If
.SearchSubFolders = True
.FileName = strRefNameAndExt
.MatchTextExactly = True
.Execute
strReturnedPath = .FoundFiles.Item(1)
strReturnedPath = .FileName
End With
For Each ref In Application.References'If reference doesn't already exist...
Exit Function
End If
Next
References.AddFromFile
(strReturnedPath) '...then add the reference.
Exit_AddReference:
Exit Function
Error_AddReference:
Call ErrorHandlerCustom
("mdlAddReference", "AddReference")
Resume Exit_AddReference
End Function
If I put a Debug.Print statement in for the ref.FullPath
statement, here's the result:
C:\Program Files\Common Files\Microsoft
Shared\VBA\VBA332.DLL
C:\Program Files\Microsoft Office\Office\MSACC8.OLB
C:\Program Files\Common Files\Microsoft
Shared\DAO\dao350.dll
C:\WINDOWS\System32\mscomct2.ocx
C:\PROGRA~1\MICROS~2\Office10\msoutl.olb <<<<8 char.
C:\PROGRA~1\COMMON~1\System\Mapi\1033\CDO.DLL <<<<8 char.
C:\Program Files\Seagull\BarTender 6.20
\Enterprise\BarTend.exe
Notice the path name for Outlook and MAPI uses the 8-
character abbrviation, but not in the dao350.dll? How do I
get it to not do that?
Thanks!
code. It almost works, but crashes occasionally when
comparing path names, to make sure the reference doesn't
already exist.
The reason is that Sometimes ref.FullPath
returns 'C:\Program Files\Common Files\...' and other
times it returns 'C:\Progra~1\Common~1\...', and it
doesn't see these two strings as being equal. I put >>>>
and <<<< around the line where this problem is occuring.
Here's the code, passing 'cdo.dll' and 'BarTend.exe' as
reference variables:
Public Function AddReference(strRefNameAndExt As String,
Optional strRefPath As String)
'Purpose: Adds reference for new installations.
'Variables: strRefNameAndExt = The name and file extension
of the reference being added.
' strRefPath = Path name to begin
search. "c:\Program Files" is used by default,
' unless otherwise specified.
'On Error GoTo Error_AddReference
Dim strReturnedPath As String
Dim ref As Reference
With Application.FileSearch 'Search for
reference called by function.
.NewSearch
If strRefPath = "" Then
.LookIn = "C:\Program Files"
Else
.LookIn = "strRefPath"
End If
.SearchSubFolders = True
.FileName = strRefNameAndExt
.MatchTextExactly = True
.Execute
strReturnedPath = .FoundFiles.Item(1)
strReturnedPath = .FileName
End With
For Each ref In Application.References'If reference doesn't already exist...
Exit Function
End If
Next
References.AddFromFile
(strReturnedPath) '...then add the reference.
Exit_AddReference:
Exit Function
Error_AddReference:
Call ErrorHandlerCustom
("mdlAddReference", "AddReference")
Resume Exit_AddReference
End Function
If I put a Debug.Print statement in for the ref.FullPath
statement, here's the result:
C:\Program Files\Common Files\Microsoft
Shared\VBA\VBA332.DLL
C:\Program Files\Microsoft Office\Office\MSACC8.OLB
C:\Program Files\Common Files\Microsoft
Shared\DAO\dao350.dll
C:\WINDOWS\System32\mscomct2.ocx
C:\PROGRA~1\MICROS~2\Office10\msoutl.olb <<<<8 char.
C:\PROGRA~1\COMMON~1\System\Mapi\1033\CDO.DLL <<<<8 char.
C:\Program Files\Seagull\BarTender 6.20
\Enterprise\BarTend.exe
Notice the path name for Outlook and MAPI uses the 8-
character abbrviation, but not in the dao350.dll? How do I
get it to not do that?
Thanks!