Save IE generated by JavaScript using VBA

0

I'm using the routine to access a page and download a file, which uses a javascript to be generated, but it needs to be saved automatically, without user intervention.

Sub ConnectWeb()
Dim ie As InternetExplorer
Dim C
Dim ULogin As Boolean, ieForm
Dim MyPass As String, MyLogin As String
Dim Linha As Integer
Dim PN As String
MyLogin = Application.InputBox("Por Favor entre com o Login", "Empresa", Default:="User", Type:=2)
MyPass = Application.InputBox("Por favor entre com a senha", "Empresa", Default:="Password", Type:=2)

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://url"
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
ie.Document.all("cuser").innerText = MyLogin
ie.Document.all("cpass").innerText = MyPass
ie.Document.getElementById("cent").Value = "BR"

ie.Document.forms(0).submit
Do While ie.Busy
   DoEvents
Loop
PN = "D515005-5304"
'JavaScript to create file
ie.Document.parentWindow.execScript ("printPL('" & PN &         "','N%2FC','no')")


End Sub

After JavaScript appears that message of SaveAs and needed that this option was "Clicked" automatically, or better yet, that it be saved in a specific location.

    
asked by anonymous 26.07.2017 / 14:33

1 answer

0

Dear, I chose to use chrome and found that javascript sends information via url, so I used the following logic:

Sub teste()
Dim chromePath, PN As String
Dim Linha As Integer
chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
Linha = 2
Cells(Linha, "A").Select
Do While ActiveCell <> ""
    PN = Cells(Linha, "A").Value
    strURL = "http://cdroyal4.cdzodiac.com/cgi-bin/wspd_cgi.sh/WService=wslive/wpt/function.r?funct=print.pl&drawing-no=" & PN & "&prelim=no&rev=N%2FC&filename=" & PN
    Shell (chromePath & strURL)
    Linha = Linha + 1
    Cells(Linha, "A").Select
Loop

MsgBox "Complete", vbInformation, "Empresa"
End Sub

With Chrome the download is done automatically, resulting in the expected result. Thanks to all who have reviewed.

    
26.07.2017 / 18:52