首页 > Excel专区 > Excel函数 >

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

Excel函数 2021-11-25 12:06:23

'下载文件相关函数申明
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位兼容参考https://msdn.microsoft.com/library/ee691831.aspx


标签: VBA登陆下载excel文件处理例子

office教程网 Copyright © 2016-2020 https://www.office9.cn. Some Rights Reserved.