我在Access中有VBA函數,它應該根據我傳遞給它的字符串變量返回特殊文件夾(MyDocuments,Desktop等)的路徑。不過,我總是得到公衆的桌面上。「C:\用戶\公用\桌面」,而不是什麼我通過在這裏是功能代碼:忽略參數的函數?
Function SpecialFolderPath(whichFolder As String) As String
Debug.Print whichFolder
Dim objWSHShell As Object
Dim strSpecialFolderPath
Set objWSHShell = CreateObject("WScript.Shell")
SpecialFolderPath = objWSHShell.SpecialFolders(whichFolder)
Debug.Print SpecialFolderPath
Set objWSHShell = Nothing
Exit Function
ErrorHandler:
MsgBox "Error finding " & strSpecialFolder, vbCritical + vbOKOnly, "Error"
End Function
所以,不管什麼我通過在爲whichFolder
,我總是得到C:\Users\Public\Desktop
。我該如何解決這個問題?
編輯:
我打電話通過以下方式這個功能:
- DoCmd.OutputTo acOutputQuery, "BoxForecasting_Jobs", "ExcelWorkbook(*.xlsx)", SpecialFolderPath("MyDocuments") & "\BoxForecastByJobs.xlsx", False, "", , acExportQualityPrint
- Set oWB = oXL.Workbooks.Open(SpecialFolderPath("MyDocuments") & "\BoxForecastByJobs.xlsx")
經由'Debug.Print()'被印刷的正確路徑? – 2015-01-26 19:47:01
我正在測試您的代碼。與你一樣獲得同樣的回報。 – 2015-01-26 19:47:46
@LynnCrumbling - 不,Debig.Print()顯示相同的錯誤值。 – MAW74656 2015-01-26 19:48:49