2017-03-20 70 views
3

我有一個工作簿,有一些自動化功能可重新配置路徑和命運,因爲它在許多不同的文件結構中打開。如何檢查excel工作簿目前是否在MAC或Windows上工作

(例如,相同的工作簿在「//用戶/保管箱」和//用戶/文件/保管箱'打開)等

對於每個用戶,它具有不同的初始路徑。 (例如,其中一個自動化在「/ dropbox/comercial/project number」裏面創建一個文件夾結構

它在Windows中工作正常,但是當我嘗試在mac中運行它時會出現錯誤 顯然,文件路徑的權利,但「/」是對方「\」。 所以結果是像「\用戶\文件\ dropbox /商業/項目編號」

林不知道這是這個問題,但是,如果是這樣,我怎麼能解決?

IM想着做一個宏來檢查其在Mac或Windows,並且,對於每個運行,「重新配置」的用正確的符號路徑。

林不知道我是否足夠清楚。如果沒有,請問,我會盡力解釋!

謝謝!

回答

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 
+0

感謝人!很好的幫助! –

+0

沒問題:) ... –

相關問題