Link to home
Start Free TrialLog in
Avatar of Dalexan
DalexanFlag for Afghanistan

asked on

Type mismatch setting object variable

I need to open a IE window with no controls from my vb6 app (no address bar no menu items only the minimize,close and the page should be visible) I have created a class module for this but I get a type mismatch error  
------------Class module -----------------------
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Const MF_BYPOSITION = &H400
Public WithEvents objIE As InternetExplorer

Public Sub LaunchIE(ByVal strURL As String, ByVal blnToolBar As Boolean, ByVal blnStatusBar As Boolean)
    Dim SysMenu As Long, Res As Long
   
    Set objIE = CreateObject("InternetExplorer.Application")   <------------ type mismatch here.
    objIE.Visible = False
    objIE.Toolbar = blnToolBar
    objIE.StatusBar = blnStatusBar
    objIE.Visible = False
    objIE.Navigate strURL
   
    SysMenu = GetSystemMenu(objIE.hwnd, 0)
    Res = RemoveMenu(SysMenu, 6, MF_BYPOSITION)
   
End Sub

Private Sub objIE_OnQuit()
    Set objIE = Nothing
End Sub

-------------------referencing the class from another form ----------------------------
Public c1 As New ClassLaunchIE

    Dim str As String
    str = "http://www.google.com"
    Call c1.LaunchIE(str, False, False)
    DoEvents
Avatar of TRobinJames
TRobinJames

With option explicit set, you need to Dim objIE
Sorry, You did that with Public With.....  Did not see at first.
Avatar of Dalexan

ASKER

Yea Public With...
Works with just Dim objIE instead of Public WithEvents objIE As InternetExplorer.
ASKER CERTIFIED SOLUTION
Avatar of TRobinJames
TRobinJames

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What you are doing should work, but there are a ton of posts out there regarding problems with this type of thing and no solid resolutions.  I think it is a relatively easy solve for a .Net expert,etc.  I have no problem if you want to delete and re-submit.  Use a higher point total and post to several zones and tags and you'll get some of the really big fish to bite.  Problem with this site is, as soon as there are a couple of posts, others tend to leave it alone.
Avatar of Dalexan

ASKER

Thanks, it worked after I declared it by itself.
Avatar of Dalexan

ASKER

Working code below,

Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Const MF_BYPOSITION = &H400
'Public objIE As InternetExplorer

Public Sub LaunchIE(ByVal strURL As String, ByVal bVisible As Boolean, ByVal bToolBar As Boolean, ByVal bStatusBar As Boolean)
    Dim SysMenu As Long, Res As Long
    Dim objIE
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Visible = bVisible
    objIE.Toolbar = bToolBar
    objIE.StatusBar = bStatusBar
    objIE.Visible = bVisible
    objIE.Navigate strURL
   
    SysMenu = GetSystemMenu(objIE.hwnd, 0)
    Res = RemoveMenu(SysMenu, 6, MF_BYPOSITION)
   
End Sub

Private Sub objIE_OnQuit()
    Set objIE = Nothing
End Sub