XL: LibraryPath Includes Trailing Separator on Macintosh

ID: Q176803


The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition


SUMMARY

The LibraryPath property of the Application object in Microsoft Visual Basic for Applications works slightly differently in Microsoft Excel for Windows than it does in Microsoft Excel for the Macintosh. This article explains the differences and how to avoid problems when using the LibraryPath property in your Visual Basic macros and procedures.


MORE INFORMATION

You can use the LibraryPath property in Visual Basic macros and procedures in Microsoft Excel to return the path to the Library folder. The Library folder is the folder where most add-ins included with Microsoft Excel are stored.

In Microsoft Excel for Windows, the LibraryPath property appears similar to the following:


   C:\Program Files\Microsoft Office\Office\Library 
Note that there is no trailing separator (in this case, a backslash) at the end of the path.

However, in Microsoft Excel for the Macintosh, the LibraryPath property appears similar to the following:

   Macintosh HD:Microsoft Office:Microsoft Excel 5:Macro Library: 
-or-

   Macintosh HD:Microsoft Office 98:Office:Excel Add-Ins: 
Note that there is a trailing separator (in this case, a colon) at the end of the path. This may cause problems if you are writing code that is intended to work in both Microsoft Excel for Windows and Microsoft Excel for the Macintosh.

You can prevent problems from occurring by programmatically removing the trailing separator from the LibraryPath before you use it. The following example demonstrates one way in which this may be done.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp

Sample Visual Basic Procedure


   Sub GetGoodLibraryPath()

      ' Store the LibraryPath in a variable.
      xLibraryPath = Application.LibraryPath

      ' If the LibraryPath ends in a colon...
      If Right(xLibraryPath, 1) = ":" Then

         ' ...remove the colon from the end of the path.
         xLibraryPath = Left(xLibraryPath, Len(xLibraryPath) - 1)

      End If

      ' Display the corrected LibraryPath.
      MsgBox "The application's LibraryPath is " & xLibraryPath

   End Sub 
Once you have corrected the LibraryPath, you can use the PathSeparator property to add either a backslash or a colon to the end of the path, and then add a file name after the separator. Following is an example:

   xFilePath = xLibraryPath & Application.PathSeparator & "Addin.xla" 
If you use the PathSeparator property when the LibraryPath has not been corrected, you may receive an error message when you run the macro in Microsoft Excel for the Macintosh.


REFERENCES

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

Q163435 VBA: Programming Resources for Visual Basic for Applications

Additional query words: XL5 XL7 XL97 XL98

Keywords : kbprg kbdta kbdtacode KbVBA
Version : MACINTOSH:5.0,5.0a,98; WINDOWS:5.0,5.0c,7.0,7.0a,97
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.