CurDir 函数CurDir function

返回表示当前路径的 Variant (String)。Returns a Variant (String) representing the current path.


CurDir[(驱动器)]CurDir [ (drive) ]

可选_drive_ 参数是指定现有驱动器的字符串表达式The optional drive argument is a string expression that specifies an existing drive. 如果未指定驱动器或 drive 是零长度字符串 (""),则 CurDir 返回当前驱动器的路径。If no drive is specified or if drive is a zero-length string (""), CurDir returns the path for the current drive. 在 Macintosh 上,CurDir 将忽略任何指定的 drive,并且只返回当前驱动器的路径。On the Macintosh, CurDir ignores any drive specified and simply returns the path for the current drive.


此示例使用 CurDir 函数返回当前路径。This example uses the CurDir function to return the current path. 在 Macintosh 上,将忽略为 CurDir 提供的 drive 指定。On the Macintosh, drive specifications given to CurDir are ignored. 默认驱动器名称是HD, 而路径名的各个部分由冒号而不是反斜杠分隔。The default drive name is HD, and portions of the pathname are separated by colons instead of backslashes. 同样,您可以指定 Macintosh 文件夹而不是 \Windows。Similarly, you would specify Macintosh folders instead of \Windows.

' Assume current path on C drive is "C:\WINDOWS\SYSTEM" (on Microsoft Windows).
' Assume current path on D drive is "D:\EXCEL".
' Assume C is the current drive.
Dim MyPath
MyPath = CurDir    ' Returns "C:\WINDOWS\SYSTEM".
MyPath = CurDir("C")    ' Returns "C:\WINDOWS\SYSTEM".
MyPath = CurDir("D")    ' Returns "D:\EXCEL".

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.