vba 在 PC 上工作但在 Mac 上不工作的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16631503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Path working on PC but not Mac
提问by Skittles
I am having a problem with my VBA code on my mac computer. It works fine on Windows. I know it has something to do with specifying directory but I'm not sure on the right syntax.
The workbook is in a folder and then I want to specify another folder (Datatextfiles) which is in the same folder as the work book.
我的 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 <> ""
回答by user1902860
NOne of y'all are right. The proper designation for a folder separator on mac is a colon ':' Such as
你们谁都不对。mac 上文件夹分隔符的正确名称是冒号“:”,例如
ChDir "KathyStringHD:Library:WebServer:Documents:DispatchReports:InTime:"
回答by CuberChase
I think you are having a problem on the Mac because you aren't using a mac path separator for your path.
我认为您在 Mac 上遇到了问题,因为您的路径没有使用 mac 路径分隔符。
Try the following line of code:
尝试以下代码行:
strPath = MyDir & Application.PathSeparator & Datatextfiles & Application.PathSeparator