Find internet explorer is installed using vba excel

V

VJ

Hi,

Is there any way I can find out whether Internet Explorer is installed in
machine using VBA?

I already have a code in which I can open hyperlink using VBA but one of my
test machine has mac which doesnot have IE.

I need to add the error handling that If IE is not installed then Use the
Safari instead of IE.

Help would be appreciated.

Thanks
 
J

Jacob Skaria

Insert a new module and paste the below code.

Sub Macro()
If IsIEAvailable Then
'Use IE
Else
'Use Safari
End If
End Sub



Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const ERROR_SUCCESS = 0&
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE _
Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) _
And (Not SYNCHRONIZE))
Public Function IsIEAvailable() As Boolean

Dim hKeyOpen As Long
Dim lKeyResult As Long
Dim lKeyQueryLen As Long

lKeyResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths" _
& "\\IEXPLORE.EXE" & Chr$(0), &H0, KEY_ALL_ACCESS, hKeyOpen)
lKeyResult = RegQueryValueEx(hKeyOpen, "Path", 0&, 0&, 0&, _
lKeyQueryLen)
If lKeyQueryLen > 0 Then
IsIEAvailable = True
Else
IsIEAvailable = False
End If
RegCloseKey hKeyOpen

End Function
 
B

Bernie Deitrick

You could try:

Dim ie As Object
On Error Goto NoIE
Set ie = CreateObject("InternetExplorer.Application")
On Error Goto 0
Goto BrowserOK
NoIE:
On Error Goto NoSafari
Set ie = CreateObject("Safari.Application")
Goto BrowserOK
NoSafari:
Msgbox "No Browser"
Exit Sub
BrowserOK:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top