![](/img/trans.png)
[英]Sharepoint mail enabled library receives csv file, import into list
[英]Import a CSV file into Access database from SharePoint Online Document Library
我在 SharePoint Online 文檔庫中上傳了一個 CSV 文件,該文件每天更新。 我使用這個 CSV 文件來創建一些帶有 Access 數據庫的報告。 我想要實現的是將 CSV 文件自動導入 Access,而無需在本地下載和保存 CSV 文件。 我使用的代碼如下:
Sub ImportCSV()
DoCmd.TransferText TransferType:=acLinkDelim, TableName:="Daily_Report_Table", FileName:="https://mycompany.sharepoint.com/teams/Daily%20Reporting.csv", HasFieldNames:=True
End Sub
但是,它要么要求我登錄,然后說我無權訪問該文件,要么不執行說它無法加載 HTML 頁面...
不要被鏈接的標題所迷惑。
您不能直接通過 HTTP 導入/鏈接文件。 代碼為您下載文件,准備鏈接:
Sub ImportCSV()
Dim Result As Long
Dim Url As String
Dim Filename As String
Url = "https://mycompany.sharepoint.com/teams/Daily%20Reporting.csv"
Filename = "C:\Imports\DailyReporting.csv"
Result = DownloadFile(Url, Filename)
If Result = 0 Then
DoCmd.TransferText TransferType:=acLinkDelim, TableName:="Daily_Report_Table", FileName:=Filename, HasFieldNames:=True
End If
End Sub
配套代碼模塊:
Option Compare Database
Option Explicit
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
Public Function DownloadFile( _
ByVal strURL As String, _
ByVal strLocalFilename As String) _
As Long
' Download file or page with public access from the web.
' 2004-12-17. Cactus Data ApS, CPH.
' Usage, download a file:
' lngRet = DownloadFile("http://www.databaseadvisors.com/Graphics/conf2002/2002ConferencePicsbySmolin/images/dba02smolin27.jpg", "c:\happybassett.jpg")
'
' Usage, download a page:
' lngRet = DownloadFile("http://www.databaseadvisors.com/conf2002/conf200202.asp", "c:\dbaconference.htm")
' Returns 0 if success, error code if not.
' Error codes:
' -2146697210 "file not found".
' -2146697211 "domain not found".
' Limitation.
' Does not check if local file was created successfully.
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, strURL & vbNullChar, strLocalFilename & vbNullChar, 0, 0)
DownloadFile = lngRetVal
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.