在PC上工作的path,但不是Mac

我在我的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 <> "" 

你们都是正确的。 在mac上文件夹分隔符的正确名称是冒号':'如

 ChDir "KathyStringHD:Library:WebServer:Documents:DispatchReports:InTime:" 

我认为你在Mac上遇到了问题,因为你的path没有使用Macpath分隔符。

尝试下面的代码行:

 strPath = MyDir & Application.PathSeparator & Datatextfiles & Application.PathSeparator 

你传递一个无效的名字给Dir() 。 当你的代码被写入,它会通过MyDir & "/Datatextfiles*.txt" ,这显然是无效的。 您也正在更改为strPath文件夹,因此您要指定一个新的path,即strPath/strPath & "*.txt" ,这又是无效的。

或者添加尾随/strPath并删除ChDir呼叫:

 strPath = MyDir & "/Datatextfiles/" .... strExtension = Dir(strPath & "*.txt") 

或消除path,只是使用

 ChDir strPath strExtension = Dir("*.txt")