我正在尝试从本地存储在我的笔记本电脑上的.csv文件中的一个VBA函数访问存储在我公司sharepoint中的一个VBA文件:
FilePath = "https://[company].sharepoint.com/Shared%20Documents/[folder]/testCSV.csv"
Open FilePath For Input As #1
如果将.csv文件本地保存在我的膝上型计算机中,则我编写的函数可以正常工作,但在尝试通过SharePoint时会出现此错误:
Run-Time Error '52':
Bad file name or number
有趣的是,我实际上可以使用以下代码打开与Excel工作簿相同的.csv文件:
Dim FilePath As String
FilePath = "https://[company].sharepoint.com/Shared%20Documents/[folder]/testCSV.csv"
Dim wb As Workbook
Set wb = Workbooks.Open(FilePath, , , 2)
我还尝试用以下代码打开一个.txt文件:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("https://[company].sharepoint.com/Shared%20Documents/[folder]/testfile.txt", ForAppending)
f.Write "Hello world!"
f.Close
如果该文件保存在我的计算机上,但如果它保存在sharepoint上,则工作正常。
对于如何解决这个问题,有什么想法吗?
提前感谢
发布于 2022-01-27 09:31:43
下载文件首先解决了这个特定错误:
'functions for downloading
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Function DownloadFileFromWeb(strURL As String, strSavePath As String) As Long 'strSavePath includes filename
DownloadFileFromWeb = URLDownloadToFile(0, strURL, strSavePath, 0, 0)
End Function
DownloadFileFromWeb(webPath, localPath)
希望这能有所帮助
https://stackoverflow.com/questions/70699501
复制相似问题