Notifications
Clear all

Download de arquivo no IE 9 via VBA

4 Posts
2 Usuários
0 Reactions
896 Visualizações
(@djvswd)
Posts: 10
Eminent Member
Topic starter
 

Boa tarde!!!

Caros,

Antes de mais nada, gostaria de te dar parabéns pelos tópicos, pois são ótimos!! :D

Estou aprendendo a sincronizar se é assim que pode se dizer e quero automatizar um processo em um link onde extraio as informações manualmente ( onde já consegui parcialmente automatizar ) o problema que uso o I.E. 9 e não consigo fazer com que a extração aconteça pois consigo "CLICAR" no botão via código, no entanto aparece uma tela de download onde exite a opção de salvar, abrir e cancelar, porém ai que está pegando pois quero "salvar como" em uma pasta especifica, mas não consigo.
Segue o código que estou usando:

Private Sub LoginxLogout()

On Error Resume Next
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
While ie.Busy
DoEvents
Wend
ie.Visible = True

'http://10.221.241.66/olos/Login.aspx
'http://10.221.240.231/punchclockclient342/forms/login.aspx
ie.Navigate " http://10.221.241.66/olos/Login.aspx"
While ie.Busy
DoEvents
Wend

ie.Document.All("User").Value = "xxxx"
ie.Document.All("Password").Value = "xxxx"
ie.Document.All("Button1").Click

Application.Wait Now + TimeValue("00:00:05")
ie.Document.All("TopMenu_Reports").Click
Application.Wait Now + TimeValue("00:00:05")

ie.Document.All("ctl00_TopMenu_lblMenuSupReports").Click
Application.Wait Now + TimeValue("00:00:05")

ie.Document.All("ctl00_PageMenu_menu1_labelMenuTitle_reports_view_agent").Click
Application.Wait Now + TimeValue("00:00:05")

ie.Document.All("ctl00_PageMenu_menu1_submenu_reports_agentoc").Click
Application.Wait Now + TimeValue("00:00:05")

Data_Inicío = InputBox("Entre Com a Data Inicial")
ie.Document.All("ctl00_PageContent_StartDate").Value = Data_Inicío

Horário_Ini = InputBox("Entre com o Horário Esperado")
ie.Document.All("ctl00_PageContent_StartHour").Value = Horário_Ini

Data_Final = InputBox("Entre Com a Data Final")
ie.Document.All("ctl00_PageContent_EndDate").Value = Data_Final

Horário_Fim = InputBox("Entre com o Horário Esperado")
ie.Document.All("ctl00_PageContent_EndHour").Value = Horário_Fim

ie.Document.All("ctl00_PageContent_DDTemplate").Value = xxxxx
ie.Document.All("ctl00_PageContent_DDCompany").Value = xxxxx

'ie.Document.All("DDCampaign").Click

ie.Document.All("selectItem").Item(0).Checked = True

ie.Document.All("ctl00_PageContent_btn_xls").Click 'Ate aqui eu consigo clicar porém aparece a tela de download(anexo) e não consigo voltar no IE9 para continuar e salvar o arquivo. :(

End Sub

Poderia me orientar? Pois estou quase louco com essa macro....rs

Muito obrigado pela atenção!!

Douglas

 
Postado : 11/02/2014 8:17 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

você consegue adaptar esse código?

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
  
Sub DownloadFilefromWeb()
'Autor: Masaru
    Dim strSavePath As String
    Dim URL As String, ext As String
    Dim buf, ret As Long
    URL = Worksheets("References & Resources").Range("URLMSL").Value
    buf = Split(URL, ".")
    ext = buf(UBound(buf))
    strSavePath = ThisWorkbook.Path & "" & "DownloadedFile." & ext
    ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
    If ret = 0 Then
        MsgBox "Download bem sucedido!"
    Else
        MsgBox "Erro"
    End If
End Sub
 
Postado : 11/02/2014 8:50 am
(@djvswd)
Posts: 10
Eminent Member
Topic starter
 

Alexandre,

Agradeço muito a atenção!
Porém sou novo nisso...rsrs
Como adaptaria essa parte?
Terei que substituir alguma expressão?

 
Postado : 11/02/2014 10:51 am
(@djvswd)
Posts: 10
Eminent Member
Topic starter
 

Alexandre,

Pode me ajudar a entender melhor como adapto esse código, por gentileza?

 
Postado : 28/01/2016 10:46 am