我有一个工作簿,其中包含一些自动化来重新配置路径和命运,因为它在许多不同的文件结构中打开。
(例如,同一工作簿在' // user / dropbox'和// user / documents / dropbox'等等)
对于每个用户,它具有不同的初始路径。 (例如,其中一个自动化内部创建了一个文件夹结构" / dropbox / comercial / project number"。
它在Windows中工作正常,但是当我尝试在mac中运行它时会出错。 显然,文件路径是正确的,但" /"在另一边" \"。 所以结果就像" \ user \ documents \ dropbox / comercial / project number"
我不确定这是不是问题,但是,如果是,我怎么能解决?
我正在考虑制作一个宏来检查它是否在mac或windows上运行,并且,对于每个,"重新配置"带有正确符号的路径。
我不确定我是否足够清楚。如果没有,请问,我会尽力解释!
谢谢!
答案 0 :(得分:3)
两个选项:
1)使用Application.PathSeparator
代替“/” - 就像在函数中一样:
Function BuildPath(sections As Variant) As String
BuildPath = Join$(sections, Application.PathSeparator)
End Function
'// Example use
'
' Dim sections As Variant
' sections = Array("documents", "projects", "files", "myfile.xlsx")
'
' Debug.Print BuildPath(sections)
'//
' ~~> output (e.g. Windows): documents\projects\files\myfile.xlsx
2)使用条件编译来检查环境:
#If Mac Then
Const ps As String = "/"
#Else
Const ps As String = "\"
#End If
'// rest of code here, using "ps" as path separator