Click here to Skip to main content
13,736,491 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 6:03am
Updated 4 days ago
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 4 days ago
   
Thanks Dave for your imm. answer.
you have saved me a lot of time of testing.

Selenium do not support VB.
Dave Kreskowiak 4 days ago
   
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 2 days ago
   
This has nothing to do with the question that was asked.
_duDE yesterday
   
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 yesterday
   
My bad. This is what I get for trying to read code with half my brain asleep.
Alex Steinmetz yesterday
   
_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 yesterday
   
@Alex: Have you tried call WShell.Run(url, 1, false) ?
Alex Steinmetz 18hrs ago
   
Please declare "WShell" and kindly give more details.
_duDE 17hrs ago
   
CreateObject("Wscript.Shell").Run - take a look https://ss64.com/vb/run.html. Are you not familiar with VBS?
Alex Steinmetz 13hrs ago
   
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 12hrs ago
   
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
Dave Kreskowiak 10hrs 5mins ago
   
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 10hrs 20mins ago
   
SET and LET is no longer supported.

how do you get the "ACTIVE ELEMENTS" of displayed html page ???
_duDE 10hrs 10mins ago
   
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!
Alex Steinmetz 9hrs 15mins ago
   
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
Web06-2016 | 2.8.180920.1 | 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