本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

VBA非登陆下载Excel文件并处理例子

电脑教程 jiaocheng 1℃

VBA非登陆下载Excel文件并处理例子

‘下载文件相关函数申明
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 Declare Function DeleteUrlCacheEntry Lib "wininet" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Sub down()
nUrl = "下载链接"
localFilename = ThisWorkbook.Path & "/文件名.拓展名"
lngRetVal = URLDownloadToFile(0, nUrl, localFilename, 0, 0)
If Dir(localFilename, 16) <> Empty Then ‘文件存在时执行
DeleteUrlCacheEntry nUrl ‘清除缓存
Set wb = Workbooks.Open(localFilename) ‘打开文件
‘业务逻辑代码
wb.Close 0 ‘关闭文件0不保存
Kill localFilename ‘删除文件
End If
End Sub
’64位兼容参考msdn.microsoft./library/ee691831.aspx

转载请注明:范的资源库 » VBA非登陆下载Excel文件并处理例子

喜欢 (0)