Click to See Complete Forum and Search --> : Late Binding of ActiveX controls
holmmd
Nov 27th, 2000, 10:30 PM
I'm writing an application that may require browsing capabilities. This functionality will only be available on machines with that support the browser control. I know how to add controls at runtime, but can't figure out how to add a WebBrowser control.
Any useful advice?
Use the CreateObject function, which will instanitate an objectbased on that objects ProgID
- gaffa
holmmd
Nov 30th, 2000, 04:47 AM
This is what doesn't work.
I'm sure I'm missing something obvious!
Option Explicit
' Sample_1
Dim WithEvents WebBrowser1 As SHDocVw.WebBrowser_V1
' From the object browser SHDocVw.WebBrowser_V1 after loading
' SHDOCVW.DLL into the project references
'
' I don't want to include the DLL and only want to make this
' available on machines that support it, so this method is not
' really an option
Dim WithEvents WebBrowser1a As SHDocVw.WebBrowser_V1
Dim WithEvents WebBrowser1b As VBControlExtender
' Sample_2
Dim WithEvents WebBrowser2 As VBControlExtender
' From HKEY_CLASSES_ROOT\
Private Sub Sample_1()
Set WebBrowser1 = Me.Controls.Add("SHDocVw.WebBrowser_V1", "WebBrowser1", Me)
' Produces error
'
' |-----------------------------------------------------|
' |Run-time error '711': |
' | |
' |Invalid class string. |
' |Looking for object with ProgID: SHDocVw.WebBrowser_V1|
' |-----------------------------------------------------|
'
' This is because SHDocVw doesn't appear in the registry
' under HKEY_CLASSES_ROOT\
Set WebBrowser1a = CreateObject("SHDocVw.WebBrowser_V1")
' Produces error
'
' |-----------------------------------------------------|
' |Run-time error '429': |
' | |
' |ActiveX component can't create object. |
' |-----------------------------------------------------|
Set WebBrowser1b = CreateObject("WebBrowserWrapper.WebBrowserWrapper.1")
' Produces error
'
' |-----------------------------------------------------|
' |Run-time error '13': |
' | |
' |Type mismatch. |
' |-----------------------------------------------------|
With WebBrowser1
.Left = 0
' Produces error
'
' |-----------------------------------------------------|
' |Runtim error '91': |
' | |
' |Object variable with block variable not set. |
' |-----------------------------------------------------|
'
.Top = 0
.Width = Me.ScaleWidth
.Height = Me.ScaleHeight
.Navigate "http://www.vbworld.net"
End With
' All of these properties are available through autocomplete
End Sub
Private Sub Sample_2()
' The control does not have licensing information in the registry
Set WebBrowser2 = Controls.Add("WebBrowserWrapper.WebBrowserWrapper.1", "WebBrowser2", Me)
With WebBrowser2
.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
.Visible = True
.LocationURL = "http://www.vb-world.net"
' Produces error
'
' |-----------------------------------------------------|
' |Runtime error '438': |
' | |
' |Object doesn't support this property or method. |
' |-----------------------------------------------------|
'
' The property IS NOT available via autocomplete and neither
' is '.object.LocationURL'. Since the control is created and
' visible, what I was really asking I suppose is how to get at
' the properties/methods/events
End With
End Sub
Private Sub Form_Load()
Sample_1
Sample_2
End Sub
Private Sub Form_Terminate()
Set WebBrowser1 = Nothing
End Sub
[Edited by holmmd on 12-05-2000 at 03:45 AM]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.