下载 Excel 直接到驱动器 (C:\)(不需要另存为选项)VBA Excel
Download Excel direct to drive (C:\) (No save as option require) VBA Excel
我是 VBA 的新人。请帮助我将 excel 文件直接下载到我的驱动器中。我只能选择单击该元素,它会提示 "Save As" 对话框。
Application.StatusBar = "Saving - Dashboard.xlsx"
设置 InputElement = doc.querySelector("span.export[class='export excel'")
If Not InputElement Is Nothing Then
InputElement.Click
我每小时都在运行这个代码,我不能每小时都点击另存为按钮。
我想下载自动下载器,但没有成功。因为,我有管理员权限并且不符合政策。
Public 子 OpenIE_Login()
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop ''' ATTENTION - PAUSE HERE
Set doc = IE.Document
Set LoginForm = doc.forms(0)
Set InputElement = doc.querySelector("input#userName[id='userName']")
If Not InputElement Is Nothing Then
InputElement.Value = cUsername
End If
'
设置 InputElement = doc.querySelector("input.field[type='password']")
If Not InputElement Is Nothing Then
InputElement.Value = cPassword
End If
Application.StatusBar = "Saving - WokingHours.xlsx"
设置 InputElement = doc.querySelector("span.export[class='export excel'")
'将 TempStr 变暗为字符串
如果不是 InputElement 是 Nothing 那么
'TempStr = InputElement.Value
InputElement.Click
结束子
您没有发布实际下载文件的代码。在主题的标题中,您说 VBA Excel 但您的代码使用 IE object.
如果您有 URL 文件,则可以参考下面的示例下载文件。
Private Declare PtrSafe 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
Sub demo()
Dim strURL As String
Dim LocalFilePath As String
Dim DownloadStatus As Long
strURL = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
LocalFilePath = "C:\Users\panchals\Desktop\sample.txt"
DownloadStatus = URLDownloadToFile(0, strURL, LocalFilePath, 0, 0)
If DownloadStatus = 0 Then
MsgBox "File Downloaded. Check in this path: " & LocalFilePath
Else
MsgBox "Download File Process Failed"
End If
End Sub
您需要根据自己的需要修改代码。
参考:
我是 VBA 的新人。请帮助我将 excel 文件直接下载到我的驱动器中。我只能选择单击该元素,它会提示 "Save As" 对话框。
Application.StatusBar = "Saving - Dashboard.xlsx" 设置 InputElement = doc.querySelector("span.export[class='export excel'")
If Not InputElement Is Nothing Then
InputElement.Click
我每小时都在运行这个代码,我不能每小时都点击另存为按钮。
我想下载自动下载器,但没有成功。因为,我有管理员权限并且不符合政策。
Public 子 OpenIE_Login()
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop ''' ATTENTION - PAUSE HERE
Set doc = IE.Document
Set LoginForm = doc.forms(0)
Set InputElement = doc.querySelector("input#userName[id='userName']")
If Not InputElement Is Nothing Then
InputElement.Value = cUsername
End If
'
设置 InputElement = doc.querySelector("input.field[type='password']")
If Not InputElement Is Nothing Then
InputElement.Value = cPassword
End If
Application.StatusBar = "Saving - WokingHours.xlsx"
设置 InputElement = doc.querySelector("span.export[class='export excel'") '将 TempStr 变暗为字符串 如果不是 InputElement 是 Nothing 那么 'TempStr = InputElement.Value InputElement.Click
结束子
您没有发布实际下载文件的代码。在主题的标题中,您说 VBA Excel 但您的代码使用 IE object.
如果您有 URL 文件,则可以参考下面的示例下载文件。
Private Declare PtrSafe 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
Sub demo()
Dim strURL As String
Dim LocalFilePath As String
Dim DownloadStatus As Long
strURL = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
LocalFilePath = "C:\Users\panchals\Desktop\sample.txt"
DownloadStatus = URLDownloadToFile(0, strURL, LocalFilePath, 0, 0)
If DownloadStatus = 0 Then
MsgBox "File Downloaded. Check in this path: " & LocalFilePath
Else
MsgBox "Download File Process Failed"
End If
End Sub
您需要根据自己的需要修改代码。
参考: