一開始找到了檔案系統控制的函數 傳回目前路徑CurDir
不過似乎只能得到預設的路徑 一般是得到使用者路徑
而不是我要得到的當前路徑
我希望我的程式能抓excel範本所在的路徑資料
結果查了一下資料 取得當前路徑可以從物件的path屬性得到
Debug.Print Application.AltStartupPath '傳回取代啟動資料夾的名稱
Debug.Print ActiveWorkbook.Path '傳回目前工作簿的路徑(檔案未存檔時傳回空字串) "這個符合要求"
Debug.Print ActiveWorkbook.FullName '現用目前工作簿的路徑及檔案名稱(檔案未存檔時只傳回暫存檔名)
Debug.Print Application.NetworkTemplatesPath '傳回儲存範本所在的網路路徑,如果指定的網路路徑不存在,本屬性將傳回一空字串
Debug.Print Application.TemplatesPath '傳回儲存範本所在的區域路徑
Debug.Print Application.Path '傳回Excel程式完整路徑
Debug.Print Application.DefaultFilePath '傳回或者設定 Microsoft Excel 開啟檔案時使用的預設路徑
Debug.Print Application.StartupPath '傳回啟動資料夾的完整路徑
Debug.Print Application.LibraryPath '傳回程式庫資料夾的路徑
Debug.Print Application.UserLibraryPath '傳回使用者電腦上 COM 增益集安裝位置的路徑(2000以上)
Debug.Print Application.PathSeparator '傳回路徑分隔符號
Debug.Print CurDir '傳回目前的路徑(開啟舊檔時線市的路徑)
For a = 1 To 27
Cells(a, 1) = Environ(a)
Next
End Sub
能夠得到當前路徑 就可以讓這個excel放在需要載入資料的目錄下
就能正常執行了
沒有留言:
張貼留言