Calling Firefox MozillaBrowser from Visual Basic VB6

Posted on 2005-04-22
Last Modified: 2013-11-25

I have a VB app that currently user IE InternetExplorer Browser which is call using the following commands.

Dim obj As InternetExplorer
Set obj = New InternetExplorer

I'm trying to use MozillaBrowser but it doesn't work in ny app the way that IE does. ere is what I have tried.

Dim obj As MozillaBrowser
Set obj = New MozillaBrowser
Set obj = New MOZILLACONTROLLib.MozillaBrowser

Please help.
Question by:Costellot
    LVL 38

    Expert Comment

    To my knowledge, the only way to automate Mozilla is through this Active X control:
    LVL 29

    Expert Comment

    If you have mozzila installed on your computer you can set the a string in the registry and set mozzila to be default and then set it back to IE when your finsished.


    default          "C:\Program Files\Internet Explorer\iexplore.exe" -nohome

    You then just change the path to point the mozzila webbrowser location

    'Registry code...

    Option Explicit
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Const HKEY_CLASSES_ROOT = &H80000000
    Private Const HKEY_CURRENT_CONFIG = &H80000005
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const HKEY_USERS = &H80000003
    Private Const ERROR_SUCCESS = 0&
    Private Const REG_SZ = 1
    Private Const REG_DWORD = 4
    Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim keyhand As Long
        Dim X As Long
        Dim r As Long
        X = RegCreateKey(hKey, strPath, keyhand)
        X = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
        X = RegCloseKey(keyhand)
    End Sub

    Private Sub Command1_Click()
    'set IE to default browser
    Call SaveString(HKEY_CLASSES_ROOT, "http\shell\open\command", "", "C:\Program Files\Internet Explorer\iexplore.exe") ' string value
    End Sub

    Private Sub Command2_Click()
    'set Mozilla to default browser
    Call SaveString(HKEY_CLASSES_ROOT, "http\shell\open\command", "", "C:\Program Files\Mozilla\firefox.exe") ' string value

    End Sub
    LVL 32

    Expert Comment

    If you're just looking to open a page in Firefox, all you have to do is this:

    Place this in a module / form:

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Place this where you want to use it:
    lRet = ShellExecute(Me.hwnd, "open", "C:\Program Files\mozilla\firefox\firefox.exe", "", vbNullString, 1)

    You'll have to change the path to mozilla, I am not sure if I have typed it correctly.

    Author Comment

    Thanks for all of your feedback.

    Does anyone konw how to obtin the Document Object Model of a Firefox web page page once it has been loaded in the browser?

    LVL 38

    Accepted Solution

    As I mentioned before, you can only do this using the active x control linked above.  The document object model is uses is identical to that of the IE webbrowser object.

    Add MozillaControl 1.0 Type Library to your components, then drag a browser window onto your form.  In your form code put:

    Option Explicit

    Private Sub Form_Load()
        Me.MozillaBrowser1.Navigate ""
    End Sub

    Private Sub MozillaBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        If pDisp Is MozillaBrowser1.Object Then
            Debug.Print MozillaBrowser1.Document.Title
        End If
    End Sub


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now