Solved

Change from Early to Late Binding

Posted on 2007-04-03
10
552 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:BillPowell
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
Set shlShellWindows = CreateObject("Shell.Application")
Set ie = CreateObject("Shell.InternetExplorer")
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
CreateObject("InternetExplorer.Application")
0
 
LVL 11

Author Comment

by:BillPowell
Comment Utility
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.
0
 
LVL 12

Expert Comment

by:jkaios
Comment Utility
Where exactly (what line) in your code does the error occurs?
0
 
LVL 11

Author Comment

by:BillPowell
Comment Utility
This is the offending line:
Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 39

Assisted Solution

by:stevbe
stevbe earned 100 total points
Comment Utility
EDDTK has is correctly for an individual ie window
    Set ie = CreateObject("InternetExplorer.Application")

0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 100 total points
Comment Utility
Don't think you can call

Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")

because it is hidden and must be go through the object to create.

I try this one

Set shlShellWindows = CreateObject("Shell.Application")

but has no luck

The other one should be

Set ie = CreateObject("InternetExplorer.Application")
0
 
LVL 27

Accepted Solution

by:
Ark earned 300 total points
Comment Utility
Private Sub Command1_Click()
   Dim sha, shw
   Set sha = CreateObject("Shell.Application")
   For Each shw In sha.windows
      Debug.Print shw.LocationURL
   Next
End Sub
0
 
LVL 11

Author Comment

by:BillPowell
Comment Utility
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!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

772 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

9 Experts available now in Live!

Get 1:1 Help Now