Click here to Skip to main content
13,795,074 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
How to change the following line to default web browser:
Dim WebBrowser1 as object = CreatObject("InternetExplorer.Application")


What I have tried:

1. Dim WebBrowser1 as object = CreatObject("LaunchWinApp.exe %1")
2. Dim WebBrowser1 as object = CreatObject("default")
Posted 13-Oct-18 7:03am
Updated 15-Oct-18 2:34am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You don't. AFAIK, IE is the only browser exposed through a COM interface.

Next, treating the returned class object from CreateObject "As Object", will only get you access to the methods and properties that an Object exposes, not the properties and methods of the returned class object you created.

If you want to control all of the major browsers, look into Selenium[^].
  Permalink  
Comments
Alex Steinmetz 15-Oct-18 6:56am
   
Thanks Dave for your imm. answer.
you have saved me a lot of time of testing.

Selenium do not support VB.
Dave Kreskowiak 15-Oct-18 8:26am
   
What makes you say it's not supported?

It works in VB.NET.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

[EDITED]
Use this code (VBS/VBA) to open a URL with standard browser:

Dim webbrowser2
Set webbrowser2 = CreateObject("Wscript.Shell")
If webbrowser2 Is Nothing Then
  MsgBox "Error on creating WebBrowsewr object"
Else
  webbrowser2.Run "http:\\www.google.com", 1, False
End If


Take a look: Script Show default browser (updated for Win10)[^]

wscript.echo browser 
 
' Indentify default web browser 
' By Jørgen Bigom  
' Updated Oct. 2015 
Function Browser 
    Const HKEY_CURRENT_USER = &H80000001 
    Const strKeyPath = "Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" 
    Const strValueName = "Progid" 
    Dim strValue, objRegistry, i 
' Browser list: 
    Dim blist(6,1) 
    blist(0,0) = "Intermet Explorer"    : blist(0,1) = "ie" 
    blist(1,0) = "Edge"                    : blist(1,1) = "appxq0fevzme2pys62n3e0fbqa7peapykr8v" 
    blist(2,0) = "Firefox"                : blist(2,1) = "firefox" 
    blist(3,0) = "Chrome"                : blist(3,1) = "chrome" 
    blist(4,0) = "Safari"                : blist(4,1) = "safari" 
    blist(5,0) = "Avant"                : blist(5,1) = "browserexeurl" 
    blist(6,0) = "Opera"                : blist(6,1) = "opera" 
    Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv") 
    objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue 
    If IsNull(strValue) Then 
        browser = "Intermet Explorer (Windows standard)": Exit Function 
    Else 
        For i = 0 To Ubound (blist, 1) 
            If Instr (1, strValue, blist(i,1), vbTextCompare) Then browser = blist(i,0) & " - User choice": Exit Function 
        Next 
    End If 
    browser = "Unknown web browser! (signature: '" & strValue & "')" 
End Function
  Permalink  
v2
Comments
Dave Kreskowiak 17-Oct-18 8:25am
   
This has nothing to do with the question that was asked.
_duDE 18-Oct-18 10:46am
   
This is the possibility to get the staandard browser by using the windows registry. Why should that not to be relevant to asked question?
Dave Kreskowiak 18-Oct-18 11:54am
   
My bad. This is what I get for trying to read code with half my brain asleep.
Alex Steinmetz 18-Oct-18 13:43pm
   
_dude
Can you be more specific.

Looks like you all missing the main point.
I am not trying to control all of the major browsers.

what I am trying is to run the default browser as: "Process.Start(url)"

and get the HtmlDocuments and the active elements

so I can post my UserName and Password.
_duDE 18-Oct-18 14:33pm
   
@Alex: Have you tried call WShell.Run(url, 1, false) ?
Alex Steinmetz 19-Oct-18 1:54am
   
Please declare "WShell" and kindly give more details.
_duDE 19-Oct-18 2:47am
   
CreateObject("Wscript.Shell").Run - take a look https://ss64.com/vb/run.html. Are you not familiar with VBS?
Alex Steinmetz 19-Oct-18 6:26am
   
No, I am not familiar with VB script.

Still can not get the Active Elements.

Code
Dim webbrowser2 As Object = CreateObject("Wscript.Shell").Run(MemSite(CurrCell), 1, False)
Dim HtmlDoc, HtmlElem As Object
HtmlDoc = webbrowser2.Document
HtmlElem = HtmlDoc.all.item(0)
If HtmlElem.tagname = "HTML" Then
------
End if
_duDE 19-Oct-18 7:22am
   
You need to use "Set" to create objects in VBS/VBA.
Try this (VBS):

Dim webbrowser2
Set webbrowser2 = CreateObject("Wscript.Shell")
If webbrowser2 Is Nothing Then
MsgBox "Error on creating WebBrowsewr object"
Else
webbrowser2.Run "http:\\www.google.com", 1, False
End If
Alex Steinmetz 19-Oct-18 8:41am
   
SET and LET is no longer supported.

how do you get the "ACTIVE ELEMENTS" of displayed html page ???
_duDE 19-Oct-18 9:12am
   
Alex, make me a pleasure, please: save the code I gave you as test.vbs and let it run ("cscript.exe test.vbs" on console). You will see that the default browser opens the google site - that is all I can do for you now. Have no more time dude, sorry!
Dave Kreskowiak 19-Oct-18 9:17am
   
The problem with this approach is that you get a Process object back. You don't get access to the browsers DOM to be able to fill in fields from the code.
Alex Steinmetz 19-Oct-18 9:57am
   
Thank you for trying to help
Have a nice week end.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.181207.3 | Last Updated 19 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100