3

我的 Mac 计算机上的 VBA 代码有问题。它在 Windows 上运行良好。我知道这与指定目录有关,但我不确定正确的语法。
工作簿位于一个文件夹中,然后我想指定另一个文件夹(Datatextfiles),该文件夹与工作簿位于同一文件夹中。

'Change Path
Dim strPath As String
Dim MyDir As String
MyDir = ActiveWorkbook.Path
strPath = MyDir & "/Datatextfiles/"

Dim strExtension As String

 'Stop Screen Flickering
Application.ScreenUpdating = Falsew

 'Change extension
strExtension = Dir(strPath & "*.txt")

clearData

Do While strExtension <> ""
4

2 回答 2

6

你们没有一个是对的。mac 上文件夹分隔符的正确名称是冒号 ':' 例如

ChDir "KathyStringHD:Library:WebServer:Documents:DispatchReports:InTime:"
于 2013-06-25T15:53:29.423 回答
3

我认为您在 Mac 上遇到了问题,因为您没有使用 mac 路径分隔符作为路径。

尝试以下代码行:

strPath = MyDir & Application.PathSeparator & Datatextfiles & Application.PathSeparator
于 2013-05-19T10:48:13.293 回答