|
-
Nov 29th, 2006, 04:51 PM
#1
Thread Starter
Lively Member
Clear IE Browser Cache and History with VBA
Hi
Is there a way to clear out the cache and history using VBA code? (not using sendkeys). i know how to clear the cookies folder, but cache and history are an unknown. any help would be appreciated.
thanks
tx
-
Nov 29th, 2006, 04:54 PM
#2
Re: Clear IE Browser Cache and History with VBA
Yes, but from which office app and what exactly are you trying to do?
moved
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 29th, 2006, 04:56 PM
#3
Thread Starter
Lively Member
Re: Clear IE Browser Cache and History with VBA
 Originally Posted by RobDog888
Yes, but from which office app and what exactly are you trying to do?
moved
from Excel, it is a macro in Excel. i want to be able to clear out the IE browser cache and history using a macro.
thanks for the reply
-
Dec 2nd, 2006, 11:36 PM
#4
Re: Clear IE Browser Cache and History with VBA
Hi
here is something directly from the microsoft's website...
1) CLEARING CACHE
Use WinInet API FindFirstURLCacheEntry to find the first cache entry and use FindNextUrlCacheEntry to enumerate through the cache. Use DeleteUrlCacheEntry to delete each entry.
Note that FindFirstUrlCacheGroup, FindNextUrlCacheGroup, and DeleteUrlCacheGroup are used in the following example. These API functions have only became available with Internet Explorer 5, so proper checking as shown is needed to prevent errors.
The following steps show you how to use the WinInet API in Visual Basic to clear all the files in the cache.
1. Create a new Visual Basic standard EXE project.
2. Create a command button under form1.
3. Paste the following code in the module of form1:
VB Code:
Option Explicit
Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
ByVal dwFlags As Long, _
ByVal dwFilter As Long, _
ByRef lpSearchCondition As Long, _
ByVal dwSearchCondition As Long, _
ByRef lpGroupId As Date, _
ByRef lpReserved As Long) As Long
Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _
ByVal hFind As Long, _
ByRef lpGroupId As Date, _
ByRef lpReserved As Long) As Long
Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
ByVal sGroupID As Date, _
ByVal dwFlags As Long, _
ByRef lpReserved As Long) As Long
Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _
ByVal lpszUrlSearchPattern As String, _
ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
szRestOfData(1024) As Long
End Type
Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _
ByVal lpszUrlName As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _
ByVal hEnumHandle As Long, _
ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Const CACHGROUP_SEARCH_ALL = &H0
Private Const ERROR_NO_MORE_FILES = 18
Private Const ERROR_NO_MORE_ITEMS = 259
Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2
Private Const BUFFERSIZE = 2048
Private Sub Command1_Click()
Dim sGroupID As Date
Dim hGroup As Long
Dim hFile As Long
Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO
Dim iSize As Long
On Error Resume Next
' Delete the groups
hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0)
' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
If Err.Number <> 453 Then
If (hGroup = 0) And (Err.LastDllError <> 2) Then
MsgBox "An error occurred enumerating the cache groups" & Err.LastDllError
Exit Sub
End If
Else
Err.Clear
End If
If (hGroup <> 0) Then
'we succeeded in finding the first cache group.. enumerate and
'delete
Do
If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then
' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
If Err.Number <> 453 Then
MsgBox "Error deleting cache group " & Err.LastDllError
Exit Sub
Else
Err.Clear
End If
End If
iSize = BUFFERSIZE
If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then
MsgBox "Error finding next url cache group! - " & Err.LastDllError
End If
Loop Until Err.LastDllError = 2
End If
' Delete the files
sEntryInfo.dwStructSize = 80
iSize = BUFFERSIZE
hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize)
If (hFile = 0) Then
If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
GoTo done
End If
MsgBox "ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError
Exit Sub
End If
Do
If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0))) _
And (Err.LastDllError <> 2) Then
Err.Clear
End If
iSize = BUFFERSIZE
If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
MsgBox "Error: Unable to find the next cache entry - " & Err.LastDllError
Exit Sub
End If
Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
done:
MsgBox "cache cleared"
Command1.Enabled = True
End Sub
Hope this helps....
Let me see if i can find something for the 'History'
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 3rd, 2006, 12:12 AM
#5
Thread Starter
Lively Member
Re: Clear IE Browser Cache and History with VBA
thanks
i found something very similar, but the history option is still somewhat elusive.
also, was wondernig if there is a way to tweak the code so it is not form dependent.
tx
-
Dec 3rd, 2006, 06:58 AM
#6
Re: Clear IE Browser Cache and History with VBA
I think I found something...
I am not sure. i haven't tested it yet...
VB Code:
' Clear the IE History
Public Sub ClearIEHistory()
Const HKEY_CURRENT_USER = &H80000001
Dim sKey As String
sKey = "Software\Microsoft\Internet Explorer\TypedURLs"
' delete the key that contains the URLs the history
DeleteRegistryKey HKEY_CURRENT_USER, sKey
' recreate the key, empty
CreateRegistryKey HKEY_CURRENT_USER, sKey
End Sub
you will require the DeleteRegistryKey and CreateRegistryKey routines which are mentioned below:
DELETE REGISTRY KEY
VB Code:
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String) As Long
' Delete a registry key
'
' Under Windows NT it doesn't work if the key contains subkeys
Sub DeleteRegistryKey(ByVal hKey As Long, ByVal KeyName As String)
RegDeleteKey hKey, KeyName
End Sub
CREATE REGISTRY KEY
VB Code:
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
"RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As Long, ByVal dwOptions As Long, _
ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, _
phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As _
Long
Const KEY_READ = &H20019 ' ((READ_CONTROL Or KEY_QUERY_VALUE Or
' KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not
' SYNCHRONIZE))
Const REG_OPENED_EXISTING_KEY = &H2
' Create a registry key, then close it
' Returns True if the key already existed, False if it was created
Function CreateRegistryKey(ByVal hKey As Long, ByVal KeyName As String) As _
Boolean
Dim handle As Long, disposition As Long
If RegCreateKeyEx(hKey, KeyName, 0, 0, 0, 0, 0, handle, disposition) Then
Err.Raise 1001, , "Unable to create the registry key"
Else
' Return True if the key already existed.
CreateRegistryKey = (disposition = REG_OPENED_EXISTING_KEY)
' Close the key.
RegCloseKey handle
End If
End Function
I don't know if this is what you want... Hope it helps
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 5th, 2006, 03:36 AM
#7
Thread Starter
Lively Member
Re: Clear IE Browser Cache and History with VBA
thanks for the code. it clears the address bar it seems, but not the history.
thanks for the input
-
May 24th, 2007, 09:23 AM
#8
New Member
Re: Clear IE Browser Cache and History with VBA
I am trying to do something similar in excel but am not sure how I can create a new EXE project? Can I run the same code from a module?
Also will this work for IE7?
Any inputs will be very helpful as I just started coding in VB-Excel. thank you
-
Sep 30th, 2008, 09:12 AM
#9
New Member
Re: Clear IE Browser Cache and History with VBA
Hi,
I am newbie to VBA.
Thank you very much for ur code.
It saved my life at the dead end.
Its working fine in my environment Window XP and MsWord 2003
Thanks a lot.
With Regards,
Ashok,
 Originally Posted by koolsid
Hi
here is something directly from the microsoft's website...
1) CLEARING CACHE
Use WinInet API FindFirstURLCacheEntry to find the first cache entry and use FindNextUrlCacheEntry to enumerate through the cache. Use DeleteUrlCacheEntry to delete each entry.
Note that FindFirstUrlCacheGroup, FindNextUrlCacheGroup, and DeleteUrlCacheGroup are used in the following example. These API functions have only became available with Internet Explorer 5, so proper checking as shown is needed to prevent errors.
The following steps show you how to use the WinInet API in Visual Basic to clear all the files in the cache.
1. Create a new Visual Basic standard EXE project.
2. Create a command button under form1.
3. Paste the following code in the module of form1:
VB Code:
Option Explicit
Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
ByVal dwFlags As Long, _
ByVal dwFilter As Long, _
ByRef lpSearchCondition As Long, _
ByVal dwSearchCondition As Long, _
ByRef lpGroupId As Date, _
ByRef lpReserved As Long) As Long
Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _
ByVal hFind As Long, _
ByRef lpGroupId As Date, _
ByRef lpReserved As Long) As Long
Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
ByVal sGroupID As Date, _
ByVal dwFlags As Long, _
ByRef lpReserved As Long) As Long
Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _
ByVal lpszUrlSearchPattern As String, _
ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
szRestOfData(1024) As Long
End Type
Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _
ByVal lpszUrlName As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _
ByVal hEnumHandle As Long, _
ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Const CACHGROUP_SEARCH_ALL = &H0
Private Const ERROR_NO_MORE_FILES = 18
Private Const ERROR_NO_MORE_ITEMS = 259
Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2
Private Const BUFFERSIZE = 2048
Private Sub Command1_Click()
Dim sGroupID As Date
Dim hGroup As Long
Dim hFile As Long
Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO
Dim iSize As Long
On Error Resume Next
' Delete the groups
hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0)
' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
If Err.Number <> 453 Then
If (hGroup = 0) And (Err.LastDllError <> 2) Then
MsgBox "An error occurred enumerating the cache groups" & Err.LastDllError
Exit Sub
End If
Else
Err.Clear
End If
If (hGroup <> 0) Then
'we succeeded in finding the first cache group.. enumerate and
'delete
Do
If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then
' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
If Err.Number <> 453 Then
MsgBox "Error deleting cache group " & Err.LastDllError
Exit Sub
Else
Err.Clear
End If
End If
iSize = BUFFERSIZE
If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then
MsgBox "Error finding next url cache group! - " & Err.LastDllError
End If
Loop Until Err.LastDllError = 2
End If
' Delete the files
sEntryInfo.dwStructSize = 80
iSize = BUFFERSIZE
hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize)
If (hFile = 0) Then
If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
GoTo done
End If
MsgBox "ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError
Exit Sub
End If
Do
If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0))) _
And (Err.LastDllError <> 2) Then
Err.Clear
End If
iSize = BUFFERSIZE
If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
MsgBox "Error: Unable to find the next cache entry - " & Err.LastDllError
Exit Sub
End If
Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
done:
MsgBox "cache cleared"
Command1.Enabled = True
End Sub
Hope this helps....
Let me see if i can find something for the 'History' 
-
Oct 3rd, 2008, 02:31 AM
#10
New Member
Re: Clear IE Browser Cache and History with VBA
Hi All,
It was working in XP and Ms word 2002 Environment.
When I migrated my application to Windows 2003 and Ms word 2003. There is a exception given as err.LastDllError=87.
Please help me asap.
I managing with the last result in XP environment. I need to migrate to windows 2003.
Solution applaudable.
With regards,
AshokKumar.
-
Dec 5th, 2008, 09:57 PM
#11
Fanatic Member
Re: Clear IE Browser Cache and History with VBA
Keep it simple
Sub Clear_Temp_Files()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 "
End Sub
Sub Clear_Cookies()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"
End Sub
Sub Clear_History()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
End Sub
Sub Clear_Form_Data()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16"
End Sub
Sub Clear_Saved_Passwords()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"
End Sub
Sub Clear_All()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"
End Sub
Sub Clear_Clear_Add_ons_Settings()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"
End Sub
-
Feb 18th, 2009, 05:40 AM
#12
New Member
Re: Clear IE Browser Cache and History with VBA
Awww!
Its simple to use!
Thanks Technorobbo!
-
Sep 13th, 2009, 11:59 PM
#13
Fanatic Member
Re: Clear IE Browser Cache and History with VBA
I am in AWEEEEEE
Very good.
-
Sep 14th, 2009, 01:04 AM
#14
Fanatic Member
Re: Clear IE Browser Cache and History with VBA
I wonder if there is also a simple shell command to change proxy settings in internet explorer.
-
Dec 10th, 2011, 07:02 AM
#15
Junior Member
Re: Clear IE Browser Cache and History with VBA
hi, i want to set internet zone setting to custom level...(high or low) with vb6
is there any way to do this.?
or any other way?
help please.
i just want to disable or enable java scripting in web browser with vb6.
i'll do it manually and it's working perfect. but i want to do this with my project automatically with coding.
anyone here to solve this problem.
thankx in advance.
-
Dec 11th, 2011, 01:00 AM
#16
Junior Member
Re: Clear IE Browser Cache and History with VBA
hi, i want to set internet zone setting to custom level...(high or low) with vb6
is there any way to do this.? and adding or removing site to trusted zone or restricted zone.
Example:
to clear ie history.
Code:
Sub Clear_History()
Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"
End Sub
or any other way?
help please.
i just want to disable or enable java scripting in web browser with vb6.
i'll do it manually and it's working perfect. but i want to do this with my project automatically with coding.
anyone here to solve this problem.
-
May 31st, 2012, 06:42 AM
#17
New Member
Re: Clear IE Browser Cache and History with VBA
Hi,
I'm sorry that I answer (to) the old question, but I want not open a new topic.
My code is the following:
For an example:
Private Sub xxxx
Code:
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 ")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255")
Shell("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351")
End Sub
Best regards
TheSuperego
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|