# Surfing the web via Excel: dealing with site modal window



## Nelson78 (Mar 8, 2019)

Hello everybody. 

I'm in troubles while surfing a web site: the deadlock is the modal window you can see in the image.

https://imgur.com/a/iq4KSDY

It absolutely blocks every Excel actions: I've to manually click "OK" in order to unblock the process.

I've tried the following solution, but unsuccessfully.

(the *red line* is the instruction triggering the window. 


```
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Public Const BM_CLICK = &HF5&



Sub navigatewebsite()

'do stuff: login to the site and navigating

Dim i As Long, hWND As Long, childHWND As Long
'class = rgRow
Dim elements As Object
    Set elements = HTMLdoc.getElementsByClassName("rgRow")
Dim ele As Object

    For Each ele In elements
        
        If ele.innerText = "3625" Or "3626" Or "3628" Or "3630" Or _
            "3631" Or "3649" Or "3651" Or "3658" Or "6376" Or _
            "3627" Or "3650" Or "3659" Or "3652" Then

                 [COLOR="#FF0000"][B]ele.Click[/B][/COLOR]
 
                               While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE     
                                DoEvents                                               
    
                                      If IE.Busy Then
                                             DoEvents
                                             hWND = FindWindow(vbNullString, "Messaggio della pagina Web")
                                                        If hWND <> 0 Then childHWND = FindWindowEx(hWND, ByVal 0&, "Button", "OK")
                                                        If childHWND <> 0 Then SendMessage childHWND, BM_CLICK, 0, 0
                                      End If
                
                               Wend

           Exit For
        End If   'end If ele.innerText
    Next ele

'do stuff

end sub
```

Probably the approach is wrong: may be I need to work with two Excel instances or something like that?

Thank's in advance for your suggestion.


----------



## John_w (Mar 8, 2019)

It looks like a JavaScript Confirm box.  Have you tried changing the element's o_nclick attribute and then clicking it?  See https://www.mrexcel.com/forum/excel...essage-box-popup-post2109894.html#post2109894


----------



## Nelson78 (Mar 11, 2019)

It seems harder.
I cannot find any o-nclick in the html.

The popup is probably triggered via the following function:



```
function RowS (sender, args) {

                        var sSite = document.getElementById("cSite").control._value;
            if (sSite == "")
                sSite = 0;
            var sTeam = document.getElementById("cTeam").control._value;
            if (sTeam == "")
                sTeam = 0;
            var Export_Type = ".xls";
            if (confirm(' Vuoi esportare i dati in un file Excel (.xls)?')) {
                xmlDocF = new ActiveXObject("Microsoft.XMLDOM");
                xmlDocF.async = false;
                xmlDocF.load("azClient.xml")
                WebMethod(xmlDocF, "SaveExport")
                NewField(xmlDocF, "idMarket", document.getElementById("hidIdMarket").value)
                NewField(xmlDocF, "type", 'output')
                NewField(xmlDocF, "date_from", document.getElementById("DayPicker1").value)
                NewField(xmlDocF, "date_to", document.getElementById("DayPicker2").value)
                NewField(xmlDocF, "id_type", args.getDataKeyValue("code1"))
                NewField(xmlDocF, "idSite", sSite)
                NewField(xmlDocF, "idTeam", sTeam)
                NewField(xmlDocF, "idLogin", document.getElementById("hidLogin").value)
                NewField(xmlDocF, "Export_Type", Export_Type)
                NewField(xmlDocF, "idMarket", document.getElementById("hidIdMarket").value)
                NewField(xmlDocF, "level", '1')
                WsAdminService.wsadmin.GeneralMethodOutsourcer(xmlDocF.documentElement.xml, OnCompleteCreaExport, OnFail);
            }
        }
```


----------



## John_w (Mar 11, 2019)

I've don't know if this will work because I've never done it before, but if the script is in the HTMLdocument and not a separate .js file you could try changing the "if (confirm(....))" to "if (true)" like this:

```
Dim HTMLdoc As HTMLDocument
    Set HTMLdoc = IE.document
    Dim script As HTMLScriptElement
    Dim p1 As Long, p2 As Long
    Set script = HTMLdoc.getElementById("the script id")    'or getElementsByTagName, etc.
    p1 = InStr(1, script.outerHTML, "if (confirm(", vbTextCompare)
    If p1 > 0 Then
        p2 = InStr(p1, script.outerHTML, "))")
        script.outerHTML = Left(script.outerHTML, p1 - 1) & "if (true)" & Mid(script.outerHTML, p2 + 2)
    End If
```
and then trigger the element which runs the script.


----------



## Nelson78 (Mar 12, 2019)

John_w said:


> I've don't know if this will work because I've never done it before, but if the script is in the HTMLdocument and not a separate .js file you could try changing the "if (confirm(....))" to "if (true)" like this:
> 
> ```
> Dim HTMLdoc As HTMLDocument
> ...



I cannot find reference to the script such as 


```
Set script = [COLOR="#FF0000"]HTMLdoc.getElementById[/COLOR]("the script id")    'or [COLOR="#FF0000"]getElementsByTagName[/COLOR], etc.
```

I need some more hints.

Where should I search?


----------



## John_w (Mar 12, 2019)

Did you change "the script id" to the actual id attribute of the script?  

Another way, if the script has a name attribute, is:

```
Set script = HTMLdoc.getElementsByName("the script name")(0)
```
assuming the script is the first (0th) element with name="the script name".

Otherwise, loop through the HTMLDocument.Scripts collection looking for some text in the script, by replacing the Set script line with:

```
Dim i As Long
    i = 0
    While i < HTMLdoc.scripts.Length And script Is Nothing
        If InStr(1, HTMLdoc.scripts(i).outerHTML, "function RowS", vbTextCompare) Then Set script = HTMLdoc.scripts(i)
        i = i + 1
    Wend
```
Remember, you need to set a reference to MS HTML Object Library, which I always recommend when developing code.


----------



## Nelson78 (Mar 13, 2019)

I've been narrowing the working area, but something is getting wrong.

Below some of the reference points:

Looping in the HTML document, we can detect 38 times the string 

```
<scrip_t
```
we have to work on the 6th occurrence.

This is its framework of the 6th occurence:
- start with 
	
	
	
	
	
	



```
<scrip_t type="text/javascript" language="javascript">
```
- ending with 
	
	
	
	
	
	



```
</scrip_t>
```
- number of characters: beyond 8000
- number of functions: 7
- function we have to manipulate: the 2nd
- the string _if (confirm('Vuoi esportare i dati in un file Excel (.xls)?'))_ is detected 4 times

Maybe there is something wrong in identifying the values of p1 and p2.

ps Of course, it is an intranet site not surfable from outside the company.


----------



## John_w (Mar 13, 2019)

My last code looks for the script containing "function RowS", so it should find your script.  However I've now tested my previous code on a real HTML page and it should change script.innerHTML, not outerHTML.  Changing outerHTML just results in open and close script tags with nothing inside. Here is the complete code.


```
Dim script As HTMLScriptElement
    Dim i As Long
    Dim p1 As Long, p2 As Long
    
    i = 0
    Set script = Nothing
    While i < HTMLdoc.Scripts.Length And script Is Nothing
        If InStr(1, HTMLdoc.Scripts(i).outerHTML, "function RowS", vbTextCompare) Then Set script = HTMLdoc.Scripts(i)
        i = i + 1
    Wend
    
    If Not script Is Nothing Then
        p1 = InStr(1, script.innerHTML, "if (confirm(", vbTextCompare)
        If p1 > 0 Then
            p2 = InStr(p1, script.innerHTML, "))")
            script.innerHTML = Left(script.innerHTML, p1 - 1) & "if (true)" & Mid(script.innerHTML, p2 + 2)
            MsgBox script.outerHTML
        End If
    Else
        MsgBox "Script not found"
    End If
```


----------



## Nelson78 (Mar 14, 2019)

John_w said:


> My last code looks for the script containing "function RowS", so it should find your script.  However I've now tested my previous code on a real HTML page and it should change script.innerHTML, not outerHTML.  Changing outerHTML just results in open and close script tags with nothing inside. Here is the complete code.
> 
> 
> ```
> ...



Of course, it finds the correct script.

The hitch is now_ Run-time errror 600 Application-defined or object-defined error_ in the line 


```
script.innerHTML = Left(script.innerHTML, p1 - 1) & "if (true)" & Mid(script.innerHTML, p2 + 2)
```

I'm struggling to find some information in the web about this error.


----------



## John_w (Mar 14, 2019)

In that case it might not be possible to rewrite the HTML.

What are you actually trying to do, as the final outcome?  It looks like the JavaScript is downloading a .xls file, and it might be possible to bypass IE automation altogether and use XMLhttp/WinHttp to download the file, by sending the exact requests that IE would send.  There are examples on the forum showing how to do this.

Staying with IE automation, another way of closing the pop-up, if you are allowed to install third-party tools, is Orlando's SendKeys.exe - http://cpap.com.br/orlando/SendKeysMore.asp.  You would run it as Shell process, before the pop-up opens, so it is independent of Excel and would not be blocked.


----------



## Nelson78 (Mar 8, 2019)

Hello everybody. 

I'm in troubles while surfing a web site: the deadlock is the modal window you can see in the image.

https://imgur.com/a/iq4KSDY

It absolutely blocks every Excel actions: I've to manually click "OK" in order to unblock the process.

I've tried the following solution, but unsuccessfully.

(the *red line* is the instruction triggering the window. 


```
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Public Const BM_CLICK = &HF5&



Sub navigatewebsite()

'do stuff: login to the site and navigating

Dim i As Long, hWND As Long, childHWND As Long
'class = rgRow
Dim elements As Object
    Set elements = HTMLdoc.getElementsByClassName("rgRow")
Dim ele As Object

    For Each ele In elements
        
        If ele.innerText = "3625" Or "3626" Or "3628" Or "3630" Or _
            "3631" Or "3649" Or "3651" Or "3658" Or "6376" Or _
            "3627" Or "3650" Or "3659" Or "3652" Then

                 [COLOR="#FF0000"][B]ele.Click[/B][/COLOR]
 
                               While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE     
                                DoEvents                                               
    
                                      If IE.Busy Then
                                             DoEvents
                                             hWND = FindWindow(vbNullString, "Messaggio della pagina Web")
                                                        If hWND <> 0 Then childHWND = FindWindowEx(hWND, ByVal 0&, "Button", "OK")
                                                        If childHWND <> 0 Then SendMessage childHWND, BM_CLICK, 0, 0
                                      End If
                
                               Wend

           Exit For
        End If   'end If ele.innerText
    Next ele

'do stuff

end sub
```

Probably the approach is wrong: may be I need to work with two Excel instances or something like that?

Thank's in advance for your suggestion.


----------



## Nelson78 (Mar 14, 2019)

XMLhttp, actually, is one of back-up plans.

Anyway yes, the goal is to download a .xls file selecting the options from the function in post #3 .

Prior to this, I've to perform the website login.

I'll get to work.


----------



## Nelson78 (Mar 14, 2019)

John_w said:


> In that case it might not be possible to rewrite the HTML.
> 
> What are you actually trying to do, as the final outcome?  It looks like the JavaScript is downloading a .xls file, and it might be possible to bypass IE automation altogether and use XMLhttp/WinHttp to download the file, by sending the exact requests that IE would send.  There are examples on the forum showing how to do this.
> 
> Staying with IE automation, another way of closing the pop-up, if you are allowed to install third-party tools, is Orlando's SendKeys.exe - http://cpap.com.br/orlando/SendKeysMore.asp.  You would run it as Shell process, before the pop-up opens, so it is independent of Excel and would not be blocked.



XMLhttp, actually, is one of back-up plans.

Anyway yes, the goal is to download a .xls file selecting the options from the function in post #3  .

Prior to this, I've to perform the website login.

I'll get to work.


----------



## Nelson78 (Mar 18, 2019)

John_w said:


> In that case it might not be possible to rewrite the HTML.
> 
> What are you actually trying to do, as the final outcome?  It looks like the JavaScript is downloading a .xls file, and it might be possible to bypass IE automation altogether and use XMLhttp/WinHttp to download the file, by sending the exact requests that IE would send.  There are examples on the forum showing how to do this.
> 
> Staying with IE automation, another way of closing the pop-up, if you are allowed to install third-party tools, is Orlando's SendKeys.exe - http://cpap.com.br/orlando/SendKeysMore.asp.  You would run it as Shell process, before the pop-up opens, so it is independent of Excel and would not be blocked.



Studying what you suggested, I've found this thread which seems the closest to my task.

https://www.mrexcel.com/forum/excel...n-internet-explorer-web-site.html#post3404965

Then, I've followed your indications about the use of Fiddler: see the post #8  of that thread, the response I've had is structured with some differences.

Can you take a look?


```
CONNECT bbbbbbb.ccc.com:443 HTTP/1.0
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Connection: Keep-Alive
Content-Length: 0
Host: bbbbbbb.ccc.com
Pragma: no-cache

A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.

Version: 3.1 (TLS/1.0)
Random: 5C 8F BB F9 3A F8 1C 06 92 2D 9C 84 69 11 89 A1 9C C1 69 A1 19 D1 0E 66 A2 D2 BC 72 63 63 27 A4
"Time": 09/10/2102 08:31:56
SessionID: 22 18 A4 B2 77 5D 19 96 0A E0 CE 71 DF A5 C1 1B CA 7D 6E 5E 2F A7 E3 26 FA B5 93 97 AE 35 10 2F
Extensions: 
	server_name	bbbbbbb.ccc.com
	status_request	OCSP - Implicit Responder
	elliptic_curves	secp256r1 [0x17], secp384r1 [0x18]
	ec_point_formats	uncompressed [0x0]
	extended_master_secret	empty
	renegotiation_info	00
Ciphers: 
	[C014]	TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
	[C013]	TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
	[0035]	TLS_RSA_AES_256_SHA
	[002F]	TLS_RSA_AES_128_SHA
	[C00A]	TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
	[C009]	TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
	[0038]	TLS_DHE_DSS_WITH_AES_256_SHA
	[0032]	TLS_DHE_DSS_WITH_AES_128_SHA
	[000A]	SSL_RSA_WITH_3DES_EDE_SHA
	[0013]	SSL_DHE_DSS_WITH_3DES_EDE_SHA
	[0005]	SSL_RSA_WITH_RC4_128_SHA
	[0004]	SSL_RSA_WITH_RC4_128_MD5

Compression: 
	[00]	NO_COMPRESSION
```


----------



## John_w (Mar 19, 2019)

I would expect a POST or a GET.  I can't really help you further, I'm afraid.


----------



## Nelson78 (Mar 19, 2019)

John_w said:


> I would expect a POST or a GET.  I can't really help you further, I'm afraid.



It could be this:


```
POST https://bbbbbbb.ccc.com/zzzzzzz/export.aspx HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: https://bbbbbbb.ccc.com/zzzzzzz/export.aspx
Accept-Language: it-IT
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: bbbbbbb.ccc.com
Content-Length: 3309
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: SMALLipServergpcdr-www-zz_999_pool=2131189770.47873.0000; APACHE_ROUTEID=.3; .ASPXAUTH=8279F05713DC913316590536D45A28926F2EA7802B0E51E8B62B82381012231E192AC773FF6B5CE852EC1DBC1FF42FB8B8B8B1202B0BED00012FCB81BA87F437C303C1536E2A70C14B0147D6CB0845DDE8044283F9ED66898C109073293315DB967DB036A89B956938A81953B580B0118F42AE0C23FA63C47BB0468BC61FC8CC29D94FE7; idlogin=7980; Administrator=; idlogintype=CbCe1%2bmhz8Q%3d; surname=bK5WMp5Bxy3HkpUXPLDEQQ%3d%3d; name=p3XVVy1bgn8%3d; logintype=EyAH69mLrBHiLTauijBTpmkCdFCkQmMD; permession=; level1=; level2=; level3=; accesslevel=%2bRMOokPN1rM%3d; company=4nooe%2f2bm%2fw%3d; level_v=OWN9c1aiwPM%3d; username=LhcV3RoYB2EGEUGp%2b8m6pw%3d%3d; mode=5U3QQE93T%2f0%3d; idGroup=uVsxn5pQ1FE%3d; Group=UCyRSUd7vmybKEwqP8W%2bAQ%3d%3d; idFlow=4pOlZ5sPbj0%3d; SMSESSION=kDYpNlrZ0f07XJPaRjeQo+Gz+K68VaFJuvmhMjFjrbPNvRYK1KvJaSdYFZ6N4s8wg7g9juxYz2wTTd3n+OF+h3+dOW9m4bnJMt2JUOhnF+MfudRa7FfzRpCmg1qw2sqp3J6aVo1DpOGKUUcTReZg6VaXheW6DPXBBBeXB8MW4qVS0yfjfEusaXic58AlpgjwToPoUlxzZsKtDzapTaKhmJLkJLVfA408MhFLaWOeTRgAtDNirzd1z0QMozvdWbbljYrVR5lEyoRlNiqfoYTxc2GCCxNWnIvu6MK/nX8u+AMeKeHz6bFItmjew5NKW8GU4RX11rPwxwSS/aFptnNsStWS7SELXSj0ePYHKIDHM/AC+PAzLsiQvd491+X92VNseywQCjROO82udLR6GFNHt1QSnoZbN4I0CyqHTF02VaPwWuIxKmA+6Ty6Mrowy7YIVaemnd656lVElKbWb8PLqx1zCgABYh02MrxBrnoXqRBAckzS2DgDz9AsZer7Ni4F7MCxcHFtNP9YEghaYyuARJnyt/bxrEIRLCm1CS52o5GKYZt+KEdvW/0Tc+LHHGDr/Ujb7+3WUTaO7mwk9prXwvq/oIYAv+1hj2gwGb9EH7lk2uuy2HojL5YO8ddxfRyouc3zPJbh58f6ZRJMEdzhIKX6ZlwgOd3PiS2ksiEut+HxgaCEkLd4N7ZTY/AdGq2cf2SSSsPexUskdGGkffSboPXfzV/ZIovpd57etALcqAhsv0hq1Re1rKy16rtty2WhJLjMPEBfzbIkur7AE7dB5zqO1bPzZvk0HBnFNuqSKODb6SVLHNOt6YqfdWXR+M9+fqpEDg1anO7qJ9csxD15CUopsK/1/NRehnSKSbl57Dq0ZQPYd7wxMVPXrNiC8BXb1mkcRjzUjmD5GIlkFP6Umv2v9cnhLutM1E+iESy/iDs+GTzquGhYPppQNzPgwes+sqx7ynwyOta4kqxGAv+Od+Siwc+Gfc8XKZdjzbFjIO1X5VlL2WxfNaP7+f44QF4axCEMYkuJhegyR+j1eB+TRGZ/YjYh00Q0gIUyWx9hX7WBWWVe0JCSLSGXxbseIgmxt9PV501wYEYqOpGu6eHjhs+pEklT2wcAutnLZOkn9H2MSglAxNALmbGGlT72vbPF547K9+zZsrAtVxaI9XccbT9u+gt0hFIIv3OUA2jVp41OHGGBYlkZaDt/6xmZSrNVTxkLqE/4zY3CRVma+ydeeHmjXqt32a+UBdM2u9AgLcEC8uIAVPIVJmXxlsQA/U4U

hidIdMarket=20&hidToExport=858873&hidP=F&RadTabStrip1_ClientState=%7B%22selectedIndexes%22%3A%5B%5D%2C%22logEntries%22%3A%5B%5D%2C%22scrollState%22%3A%7B%7D%7D&RadGrid1_ClientState=%7B%22selectedIndexes%22%3A%5B%5D%2C%22selectedCellsIndexes%22%3A%5B%5D%2C%22unselectableItemsIndexes%22%3A%5B%5D%2C%22reorderedColumns%22%3A%5B%5D%2C%22expandedItems%22%3A%5B%5D%2C%22expandedGroupItems%22%3A%5B%5D%2C%22expandedFilterItems%22%3A%5B%5D%2C%22deletedItems%22%3A%5B%5D%2C%22hidedColumns%22%3A%5B%5D%2C%22showedColumns%22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BQp0ZWVfY29kaW50FCsAAQL3tTQUKwACFCsAAQUKdGVlX2NvZGludBQrAAEC%2BLU0FCsAAhQrAAEFCnRlZV9jb2RpbnQUKwABAvm1NBQrAAIUKwABBQp0ZWVfY29kaW50FCsAAQL6tTQUKwACFCsAAQUKdGVlX2NvZGludBQrAAECj7c0FCsAAhQrAAEFCnRlZV9jb2RpbnQUKwABApG3NGQFCFJhZEdyaWQxDxQrAAJkFwQFD1NlbGVjdGVkSW5kZXhlcxYABQtFZGl0SW5kZXhlcxYABRNTZWxlY3RlZENlbGxJbmRleGVzFgAFGUNsaWVudFVuc2VsZWN0YWJsZUluZGV4ZXMWAGQ1%2F%2FDf9MKhGDGJFTOgFXOtBemoLA%3D%3D&__VIEWSTATEGENERATOR=4D8B5332&__EVENTVALIDATION=%2FwEWFQKrrOnACQKYkpj1DwKYksCJCgKYkqiuCALT1KuKDQLT1NOeBwLT1PviBALT1KP3DgLT1IucDQL6oJ2vBQL6oMXDDwL6oO2HDQL6oJWcBwL6oP3ABQK1mdPYBAK1mfvsDgLD8oH9AQL%2F7qeoAQK%2BmYmSBQLRhNeHBAKs34rGBgVC6P6R7T8TPKdi5Seh542IILKs
```


----------



## John_w (Mar 20, 2019)

That could be the correct session.  It has form parameters such as hidIdMarket, hidToExport, etc. and __EVENTTARGET and __VIEWSTATE, etc.  These names and their values come from the form input (text, radio, checkbox, etc.) and select tags/elements in the web page.  Look at the response body - does it contain the .xls file bytes?

However, it really is impossible for me to help you, for obvious reasons.  I think there are enough tips and example code in the thread I linked to see the sort of things you should be looking for and coding for.


----------



## Nelson78 (May 14, 2019)

John_w said:


> That could be the correct session.  It has form parameters such as hidIdMarket, hidToExport, etc. and __EVENTTARGET and __VIEWSTATE, etc.  These names and their values come from the form input (text, radio, checkbox, etc.) and select tags/elements in the web page.  Look at the response body - does it contain the .xls file bytes?
> 
> However, it really is impossible for me to help you, for obvious reasons.  I think there are enough tips and example code in the thread I linked to see the sort of things you should be looking for and coding for.



I'm going back to the issue: I think to have set up in the correct way what you suggested in post number 9 of the following thread:

https://www.mrexcel.com/forum/excel...n-internet-explorer-web-site.html#post3404965


But I'm bumping into the error you set up:


```
[I]Error retrieving __VIEWSTATE from [url]https://bbbbbbb.ccc.com/zzzzzzz/export.aspx[/url][/I]
```


I suppose the reason is I've to deal with the login operation.

Analising the Fiddler, probably the point is:


```
POST https://zzzz.rrrr.com/siteminderagent/forms/login.fcc HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: https://zzzz.rrrr.com/up-password/LoginUp-Password.jsp?TARGET2=https://zzzz.rrrr.com/up-password/login/login_redirect.html
Accept-Language: it-IT
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: zzzz.rrrr.com
Content-Length: 181
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=ty62RxNsq7OMNrxOyPbDRQYDPRKIyeOJnZzf6reGxUx_W0w-g-Ul!1966933934; BIGipServerauth-zzzzzzz-www-pr_443_pool=1476550666.47873.0000; _WL_AUTHCOOKIE_JSESSIONID=OqS-53zlUnfb.qeNf9Tx; targetappl=https://bbbbbbb.ccc.com/zzzzzzz/export.aspx; SMSESSION=rX8GzWKVjOf0DYtOYQ/CW6dRyur8IDtMw9GfDbeQfaTVCCunVazCXC+7COvLy+9SoVByUmR5X85A8Vyh7CkfcS+iFsNjjvr+IMOQdm6mIQ6GNFcxfBJi57Q4QYugi4WzCA+5dQckWQU03eef20y20O1iGl8rAa/YqRkrDPpOMpzPF5ZNHvh78EAYYhS9nx9stNNe2JzbXjet3c7VdK5TH8YD5CfU0rqmRQCCxvXpzO2jalYALOh2K6Et70+ZGuwHMF/KLdse7gz7OL84PKIeX5Q3EA8huPjT1SwLJ33uaNqHTlrhlIcKBnSI4uIDG9WgEuItNtuTOHZkdfHIbO9eE5it6J79WmhrqgvdMvLKrX6HB0k200L5cGmKBAVshHtWVRplFxb5DfVk2o9MRCu1vBkZCYmEhBv/15aAukm/QsXr3+40yI8fyXO1Yf+5k4BsqrEWs5VBpOVXuNk43FKl3eGaPzYdZEYCKOmQTe5CPFP7dgMYk+I0Q81grZYbVzV49ewqQV9agc+8MhFKczn9y6ZoNgVRZ9I6DE3VyHzDlKSbew498VQ+nMwT3tgKKkTHWYz0Vb3tcnmKOJBu1GvfFkwo9FPMgeegBzzbyXeXrvSBgBNagp2a1eGIfu0qQpGvhMKL8Jn0A6OvOTSJREGQYdiNu5Ap6qo+r/s8ezfahI3JWCsjFw+cB2KVsXVZMyXk50ge28WO+VOiGMUJKArZmZ/ZKLoWT7+kHwoV8wVzbLLC6GL91lrEij9yKXZIu1OdSSaWZQ6InnJEs8JCCgZ9G2WhTLmOK8D+I9ZBe2WXWZVVQmz/z74JejNaZUH7eMHDRvt13buY8kB6+T1kazlpl3Snxinj18iWQrt8dGVud7Zs4rlfTL90PppKKs337dOvxDuJ74cjwjccvT6IX+pk1fvIyZya4MtzHnC0BmNvKuQ0/fr0/uKPiFCTEqXcpsW62aHRrhaP7XJthsjZk6V7xDxFY0jwHAYsESVaKH+HaQf6BKBTtKLXM+pOscOiBnP37tMhSd/7JQlB51cBmEYt5i2sKh+/+ocvspEjFejWgUbWu1eLthyS0SxeaROjokh2Q3HfKyH8PJry45jnlAa0t2gSReEAB0pHmF+kF6atoFkygHLDqZMpwKKlthxg7gO5Qxo8AdiQTmo9LHA/6Fo4rSc0B1/1rmbkxSnlpWOHUDjQWpfoDmRY1i+xBCr3+h8rOTdC5nDXWraBL33Vl3sxYhkN1WeR7z/X

SMENC=UTF-8&target=%2Fup-password%2Flogin%2FHome.jsp%3FTARGET%3Dhttps%3A%2F%2Fzzzz.rrrr.com%2Fup-password%2Flogin%2Flogin_redirect.html&smauthreason=0&USER=nelson78&PASSWORD=london55
```


----------



## Nelson78 (May 17, 2019)

John_w said:


> That could be the correct session.  It has form parameters such as hidIdMarket, hidToExport, etc. and __EVENTTARGET and __VIEWSTATE, etc.  These names and their values come from the form input (text, radio, checkbox, etc.) and select tags/elements in the web page.  Look at the response body - does it contain the .xls file bytes?
> 
> However, it really is impossible for me to help you, for obvious reasons.  I think there are enough tips and example code in the thread I linked to see the sort of things you should be looking for and coding for.



Could this be helpful?

https://www.codeproject.com/Articles/80314/How-to-Connect-to-a-SiteMinder-Protected-Resource


----------



## John_w (May 17, 2019)

Maybe - it's doing the same as the other links in this thread - sending form data in a POST request.  You could try WinHttpRequest instead of XMLhttp because the former handles cookies automatically.


----------



## Nelson78 (May 17, 2019)

John_w said:


> Maybe - it's doing the same as the other links in this thread - sending form data in a POST request.  You could try WinHttpRequest instead of XMLhttp because the former handles cookies automatically.



Yes, maybe it does the same, but it explicitly refers to SiteMinder.

I'm giving it a try.


----------

