Link to home
Start Free TrialLog in
Avatar of BillPowell
BillPowell

asked on

Change from Early to Late Binding

Could someone assist me in converting from early to late binding.  My attempts at changing the delcarations and set statements have given me a runtime error '420' ActiveX component can't create object.  This was working fine using early binding, however the situation requires a late binding solution.  I have simplified the Code somewhat to make it readable.  

Public Function GetMap(strValue As String)
'need shdocvw.dll - Microsoft Internet Controls
Dim strUrl As String
Dim shlShellWindows As Object
Dim expExplorer As Object
Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")
strUrl = "www.google.com"

On Error Resume Next
'Build the url string
strUrl = strUrl & strValue
'Check and see if there are any open map windows to reuse
For Each expExplorer In shlShellWindows
  If Left(expExplorer.LocationName, 7) = "Mapping" Then
    expExplorer.Navigate strUrl
    Exit Function
  End If
Next
'Open browser window and launch map
Dim ie As Object
Set ie = CreateObject("SHDocVw.InternetExplorer")
ie.Navigate strUrl
ie.Visible = True
Set expExplorer = Nothing

End Function
Avatar of stevbe
stevbe

Set shlShellWindows = CreateObject("Shell.Application")
Set ie = CreateObject("Shell.InternetExplorer")
CreateObject("InternetExplorer.Application")
Avatar of BillPowell

ASKER

Guys, I need to stick to the Microsoft Internet Controls dll if possible.  In code Im checking all internet explorer windows currently open to see if they are already at the site I need them to be.  If they are, I grab that window and change the LocationName.  If none of those windows are of the specified website, I open a new internet explorer window and navigate to a url.
Where exactly (what line) in your code does the error occurs?
This is the offending line:
Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")
SOLUTION
Avatar of stevbe
stevbe

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
and apparently  M$ neds to update their docs as I tried with the indo they have posted here:
http://msdn2.microsoft.com/en-us/library/aa969392.aspx
SOLUTION
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
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

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
Ok, heres what worked finally:
Public Function GetMap(strValue As String)
Dim strUrl As String
Dim shlShellWindows As Object
Dim expExplorer As Object
Set shlShellWindows = CreateObject("Shell.Application")
strUrl = "www.google.com"

'Build the url string
strUrl = strUrl & strValue
'Check and see if there are any open map windows to reuse
For Each expExplorer In shlShellWindows.Windows
  If Left(expExplorer.LocationName, 7) = "Google" Then
    expExplorer.Navigate strUrl
    Exit Function
  End If
Next
'Open browser window and launch map
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate strUrl
ie.Visible = True
End Function

Thank for the help guys!