The information in this article applies to:
SUMMARY
In Microsoft Excel, the Visual Basic ChDir statement will fail if the path
argument does not contain a backslash character (\). This requirement may
cause problems if you use ChDir to change to a root directory, because the
path of a root directory does not necessarily contain a backslash.
and you will receive the following error message:
The following lines of code will succeed, because they each contain a backslash:
-or-
It is possible to incorporate error-handling into a ChDir function to
prevent an error from occurring. The Visual Basic code example below
demonstrates one way to do this.
Visual Basic Code ExampleMicrosoft 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.aspThis Visual Basic code example displays an input box which asks you which drive or directory you would like to switch to. When you enter a drive or directory, the example checks whether the path you enter contains a backslash and adds one, if needed, before switching to that drive or directory. To run the example, position the insertion point in the line that reads "Sub MainMacro()" and press F5.
The If-End If routine is the error-checking procedure. Whenever you use a
ChDir statement, preceding it with the If-End If routine (or some variation
of it) can help prevent the "no backslash" error.
Additional query words: 8.00 97
Keywords : kbprg kbdta KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |