Clear Cookies, Cache, Browsing History
From Excel VBA delete cache, cookies, browsing history, temporary internet files used by IE or MSHML2 xmlhttp requests. This method is applicable to IE browser only.
To delete browser cache, cookies, temporary files of other browser like Chrome or Firefox, use the manual methods discussed at end of this topic.
1.Cache Cleaner Using InternetSetOption
Copy this code to your Excel VBA or VB project & paste it in a new module. Then call the function Clear_Cache before making any call to a Web service.
Public Declare Function InternetSetOptionStr Lib "wininet.dll" Alias "InternetSetOptionA" _ (ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As Integer Public Sub Clear_Cache() InternetSetOptionStr 0, 42, sBuf, 0 End Sub
This methods uses InternetSetOption of Wininet.dll. To know more about the parameters & syntax used in t
2.Clear Cache Using Shell
Include this one line command in your VBA code, before executing the IE.Navigate command. This will open a pop up window indicating the progress of cookies being cleared.
VBA.Shell "RunDll32.exe InetCpl.Cpl, ClearMyTracksByProcess 11", vbHide
Once this command execution completes, the browser will get content from server. During automation or a Web extract, Data mining steps, we code VBA to get data from Internet Web Pages automatically. for example: Stock quotes, Sport updates, News updates etc.,
These are very useful when the content that you are referring to in Internet is frequently getting updated. In that case, it is better to clear cache before fetching data from internet.
Other important aspect of this step is to clear the cookies. This will enable enhanced security by deleting the cookie files of any website that requires login credentials.
Clear Browser Cache Firefox & Chrome
For Chrome just follow one of these 2 steps.
- From browser settings, click ‘More Tools’ -> ‘Clear browsing Data’.
- Or click Keyboard shortcut ‘Ctrl+Shift+Del’ while browsing in Chrome.
For Firefox:
- Click on Settings from browser window.
- Select “Privacy & security’ ->History ->clear now.
- or enter ‘about:preferences#privacy’ in the URL box. and follow step 2.
Once this is done, close the browser & then try to navigate to the url that you would like to see fresh contents. Except for IE, the other methods presented in this article are manual steps, which might be helpful for readers.