Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does anyone know how to read/find the current users default browser via VBA?
(Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera Browser, etc...) I'm not talking about opening a website in the default browser, but finding out which browser the current user is using as the default one... I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER, since all users on the same computer are allowed to have their own choice of default browser - but where? A search on Google didn't help, but perhaps, I shouldn't get it from the Registry at all??? So, how to tell which browser is the default one? TIA, CE --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi Charlotte,
Sub CheckWebOptions() Dim wkbOne As Workbook Set wkbOne = Application.Workbooks(1) ' Determine the target browser. Select Case wkbOne.WebOptions.TargetBrowser Case msoTargetBrowserIE6: MsgBox "The target browser is IE6." Case msoTargetBrowserIE5: MsgBox "The target browser is IE5." Case msoTargetBrowserIE4: MsgBox "The target browser is IE4." Case msoTargetBrowserV4: MsgBox "Microsoft Internet Explorer 4.0, Netscape Navigator 4.0." Case msoTargetBrowserV3: MsgBox "Microsoft Internet Explorer 3.0, Netscape Navigator 3.0." Case Else: MsgBox "The target browser is not in the given list" End Select End Sub isabelle Le 2014-04-27 08:18, Charlotte E. a écrit : Does anyone know how to read/find the current users default browser via VBA? (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera Browser, etc...) I'm not talking about opening a website in the default browser, but finding out which browser the current user is using as the default one... I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER, since all users on the same computer are allowed to have their own choice of default browser - but where? A search on Google didn't help, but perhaps, I shouldn't get it from the Registry at all??? So, how to tell which browser is the default one? TIA, CE --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Isabelle, but it doesn't tell me, if it is Chrome, Firefox, Safari,
or another browser, but only support IE... ....and, since Windows know the default browser, it must be possible to get it in VBA also. (I did know about that one - as I said, I've already looked around the net myself) Thanks for your effort anyway :-) CE "isabelle" wrote in message ... hi Charlotte, Sub CheckWebOptions() Dim wkbOne As Workbook Set wkbOne = Application.Workbooks(1) ' Determine the target browser. Select Case wkbOne.WebOptions.TargetBrowser Case msoTargetBrowserIE6: MsgBox "The target browser is IE6." Case msoTargetBrowserIE5: MsgBox "The target browser is IE5." Case msoTargetBrowserIE4: MsgBox "The target browser is IE4." Case msoTargetBrowserV4: MsgBox "Microsoft Internet Explorer 4.0, Netscape Navigator 4.0." Case msoTargetBrowserV3: MsgBox "Microsoft Internet Explorer 3.0, Netscape Navigator 3.0." Case Else: MsgBox "The target browser is not in the given list" End Select End Sub isabelle Le 2014-04-27 08:18, Charlotte E. a écrit : Does anyone know how to read/find the current users default browser via VBA? (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera Browser, etc...) I'm not talking about opening a website in the default browser, but finding out which browser the current user is using as the default one... I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER, since all users on the same computer are allowed to have their own choice of default browser - but where? A search on Google didn't help, but perhaps, I shouldn't get it from the Registry at all??? So, how to tell which browser is the default one? TIA, CE --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Charlotte E. wrote:
Does anyone know how to read/find the current users default browser via VBA? (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera Browser, etc...) I'm not talking about opening a website in the default browser, but finding out which browser the current user is using as the default one... I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER, since all users on the same computer are allowed to have their own choice of default browser - but where? A search on Google didn't help, but perhaps, I shouldn't get it from the Registry at all??? So, how to tell which browser is the default one? Under Windows 7 & 8 (and probably Vista & 8.1): HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell \Associations \UrlAssociations\http\UserChoice\ProgID This points to an entry under HKEY_CLASSES_ROOT -- for example, in my Win8 install, it's "IE.HTTP", while in my Win7 install it's "Opera.Protocol". Under Windows XP (and 2000, if you need to support it): HKEY_CURRENT_USER\Software\Classes\http\shell\open \command There's a different key used for what's listed on XP's start menu, but I don't remember what it is. Google should know, if you need it. Under Win9x & NT4 (if you need to support *those*): HKEY_CLASSES_ROOT\http\shell\open\command -- In life, they were a motley crew: farmers, lords, cutpurses, priests. In death, they are united in a singular, benevolent purpose. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here's how I check to see what MSO apps are installed...
Const sNames$ = "Internet Explorer,Firefox,Chrome" Dim oApp As Object, sz For Each sz In Split(sNames, ",") Set oApp = CreateObject(sz & ".Application") If Not oApp Is Nothing Then Beep: Exit For Next 'sz ...but that won't tell you the default browser. I'm curious why you need to know this because passing a URL in ShellExecute() opens in the user's default browser. I suppose you could do this and query its window title for the browser name, though! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
GS wrote:
Here's how I check to see what MSO apps are installed... Const sNames$ = "Internet Explorer,Firefox,Chrome" Dim oApp As Object, sz For Each sz In Split(sNames, ",") Set oApp = CreateObject(sz & ".Application") If Not oApp Is Nothing Then Beep: Exit For Next 'sz ..but that won't tell you the default browser. I'm curious why you need to know this because passing a URL in ShellExecute() opens in the user's default browser. I suppose you could do this and query its window title for the browser name, though! Maybe documentation that was written differently for various browsers? -- There are some prices that *nobody* should be willing to pay. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does anyone know how to read/find the current users default browser via
VBA? Without reading the registry can use FindExecutable but it needs a file with an appropriate extension, simplified example ' adapt for 64bit office Private Declare Function FindExecutable Lib "shell32" _ Alias "FindExecutableA" _ (ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal sResult As String) As Long Sub Test() Dim pos As Long Dim sExt As String Dim sFile As String Dim sPath As String Dim lReturn As Long Dim sResult As String sExt = "html" sPath = Application.DefaultFilePath & "\" sFile = DummyFile(sPath, sExt, True) If Len(sFile) = 0 Then ' problem creating file ? Else sResult = Space$(260) lReturn = FindExecutable(sFile, sPath, sResult) If lReturn = 32 Then pos = InStr(sResult, Chr$(0)) MsgBox Left$(sResult, pos - 1) Else MsgBox "Error code: " & lReturn End If End If DummyFile sPath, sExt, False End Sub Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As String Dim sFile As String Dim ff As Long sFile = sPath & "Dummy." & sExt On Error Resume Next Kill sFile On Error GoTo errExit ff = FreeFile Open sFile For Append As #ff Print #ff, "dummy file" Close #ff DummyFile = "Dummy." & sExt errExit: End Function Regards, Peter T |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Awesome, Peter - it works :-)
And, not only does it tell you the browser, but also the full path to the browser... And, I've tested it with all five major browsers: Chrome, Firefox, MSIE, Opera and Safari.. And, Opera and Safari, I even tried to install on some VERY unlikely loctions :-) And, tested on both a Danish Windows 7, an English Windows XP, and even on a Windows Server OS :-) And, it was tested on XL2003, XL2007, XL2010 and XL2013 - and, also in both Danish and English versions. So, not matter the browser, the installation, the Excel, the language or the OS - it just works :-) Thanks, Peter - you saved my day :-) CE "Peter T" wrote in message ... Does anyone know how to read/find the current users default browser via VBA? Without reading the registry can use FindExecutable but it needs a file with an appropriate extension, simplified example ' adapt for 64bit office Private Declare Function FindExecutable Lib "shell32" _ Alias "FindExecutableA" _ (ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal sResult As String) As Long Sub Test() Dim pos As Long Dim sExt As String Dim sFile As String Dim sPath As String Dim lReturn As Long Dim sResult As String sExt = "html" sPath = Application.DefaultFilePath & "\" sFile = DummyFile(sPath, sExt, True) If Len(sFile) = 0 Then ' problem creating file ? Else sResult = Space$(260) lReturn = FindExecutable(sFile, sPath, sResult) If lReturn = 32 Then pos = InStr(sResult, Chr$(0)) MsgBox Left$(sResult, pos - 1) Else MsgBox "Error code: " & lReturn End If End If DummyFile sPath, sExt, False End Sub Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As String Dim sFile As String Dim ff As Long sFile = sPath & "Dummy." & sExt On Error Resume Next Kill sFile On Error GoTo errExit ff = FreeFile Open sFile For Append As #ff Print #ff, "dummy file" Close #ff DummyFile = "Dummy." & sExt errExit: End Function Regards, Peter T --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Charlotte E." wrote in message
Awesome, Peter - it works :-) Glad it works but just seen a stupid omission in the DummyFile routine. Add the If bCreate pair. Whole point of course being to delete the file when done, not recreate it again! Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As String Dim sFile As String Dim ff As Long sFile = sPath & "Dummy." & sExt On Error Resume Next Kill sFile On Error GoTo errExit If bCreate Then ff = FreeFile Open sFile For Append As #ff Print #ff, "dummy file" Close #ff End If DummyFile = "Dummy." & sExt errExit: End Function |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Charlotte E." wrote in message
Awesome, Peter - it works :-) Glad it works but just seen a stupid omission in the DummyFile routine. Add the If bCreate pair. Whole point of course being to delete the file when done, not recreate it again! Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As String Dim sFile As String Dim ff As Long sFile = sPath & "Dummy." & sExt On Error Resume Next Kill sFile On Error GoTo errExit If bCreate Then ff = FreeFile Open sFile For Append As #ff Print #ff, "dummy file" Close #ff End If DummyFile = "Dummy." & sExt errExit: End Function I was going to suggest same, but thinking this function isn't really necessary if you have a list of executable filenames!<g -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Nice!
-- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
but thinking this function isn't really necessary if you have a list
of executable filenames Uh.., I stand corrected if one doesn't already have a procedure for creating files! Since I already have this the 'Kill' statement would be included in the 'GetExecutable$()' function so it runs stand-alone and callable to return the info. -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "GS" wrote in message but thinking this function isn't really necessary if you have a list of executable filenames Uh.., I stand corrected if one doesn't already have a procedure for creating files! Since I already have this the 'Kill' statement would be included in the 'GetExecutable$()' function so it runs stand-alone and callable to return the info. Gary, not sure I follow but what I posted was only intended as example, adapt as required, typically as a function to receive an extension and return the exe name possibly with its path. If you know the location of a file with the extension no need to make a dummy, or maybe adapt to create a dummy optionally if a known *.ext doesn't exist (and kill it of course!). All in the one function or two as I posted is only style. Charlotte, although it's worked 100% in your testing it can fail, not least if there is no file association (though unlikely not to have a default browser). Return values 1 to 31 are error codes to inform what the problem was and there's a list out there somewhere if you search FindExecutable. Don't forget to adapt for 64bit if necessary including the return var as LongPtr. You didn't say what the objective was but if to launch the default browser with a given file simply use ShellExecute. Regards, Peter T |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Gary, not sure I follow but what I posted was only intended as
example, adapt as required, typically as a function to receive an extension and return the exe name possibly with its path. If you know the location of a file with the extension no need to make a dummy, or maybe adapt to create a dummy optionally if a known *.ext doesn't exist (and kill it of course!). All in the one function or two as I posted is only style. Thanks, Peter! I got that after realizing not everyone has file I/O wrappers as I have. In the interest of keeping the procedure 'generic', though, it's clearly better to use a temp dummy file as you exampled, IMO. Nice utility to have in my "mFunctions.bas". Thanks for sharing it!!! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Peter,
although it's worked 100% in your testing it can fail, if there is no file association I know, and I've already adapted the function to take this into consideration :-) The purpose for the function is in connection with working with IE Automation, if you use IE as hidden during the process. Sometimes, if the IE automation fails, IE might not get closed properly, and you can end up having a number of IE process running in the background, with no purpose, taking up resources. So, I've made a little macro, which kills all running IE processes. BUT! I don't want to kill all running IE processes, if IE is the default browser, because then I might kill an open IE window, which the user has opended on purpose, and want to keep open - thus, the need to know the default browser of the system. PS: And, the function also works with Avant Browser :-) Once, angin, thank you for your help and effort... CE "Peter T" wrote in message ... "GS" wrote in message but thinking this function isn't really necessary if you have a list of executable filenames Uh.., I stand corrected if one doesn't already have a procedure for creating files! Since I already have this the 'Kill' statement would be included in the 'GetExecutable$()' function so it runs stand-alone and callable to return the info. Gary, not sure I follow but what I posted was only intended as example, adapt as required, typically as a function to receive an extension and return the exe name possibly with its path. If you know the location of a file with the extension no need to make a dummy, or maybe adapt to create a dummy optionally if a known *.ext doesn't exist (and kill it of course!). All in the one function or two as I posted is only style. Charlotte, although it's worked 100% in your testing it can fail, not least if there is no file association (though unlikely not to have a default browser). Return values 1 to 31 are error codes to inform what the problem was and there's a list out there somewhere if you search FindExecutable. Don't forget to adapt for 64bit if necessary including the return var as LongPtr. You didn't say what the objective was but if to launch the default browser with a given file simply use ShellExecute. Regards, Peter T --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com --- Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret. http://www.avast.com |
#17
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can set a fully qualified object ref to your CreateObject()
instance so you never have to worry about other running instances. You can even make it run 'like' it's an in-process app extension so it closes automatically when your app closes. I do this for my apps that use a html.exe as a userguide. My app tracks any running instance it creates via its hwnd to ensure there's only 1 instance being used whether it's already running or not. Very easy to do with any EXE, really!<g -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#18
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "GS" wrote in message You can set a fully qualified object ref to your CreateObject() instance so you never have to worry about other running instances. You can even make it run 'like' it's an in-process app extension so it closes automatically when your app closes. I do this for my apps that use a html.exe as a userguide. My app tracks any running instance it creates via its hwnd to ensure there's only 1 instance being used whether it's already running or not. Very easy to do with any EXE, really!<g For html.exe probably best to close it (if open) with the help api, first HH_CLOSE_ALL and then HH_UNINITIALIZE (the latter should be done anyway even if not currently open but if earlier initialized) Regards, Peter T |
#19
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
For html.exe probably best to close it (if open) with the help api,
first HH_CLOSE_ALL and then HH_UNINITIALIZE (the latter should be done anyway even if not currently open but if earlier initialized) Not sure you understand me. I have created a pure VB wrapper that allows me to manage my stand-alone EXE user guide 'as though' it was a CHM running 'in-process'. It does not use the help API, but does use the following API functions... from user32.dll: EnumWindows GetClassName GetWindowText ShowWindow SetForegroundWindow IsIconic IsWindowVisible SendMessage from shell32.dll: ShellExecute ...to keep track of the EXE it's managing. All that's required to use it is the full filename of the EXE! -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Change Default Hyperlink Browser..? | Excel Programming | |||
Default ribbon to open by default when opening xls in browser | Excel Discussion (Misc queries) | |||
Excel default browser for Win2003 | Excel Discussion (Misc queries) | |||
How do I change default browser for opening WWW links from Excel? | Setting up and Configuration of Excel | |||
Default browser for web querys? | Excel Programming |