Solved

VBA for Microsoft Word:  Opening a URL

Posted on 2006-11-16
3
605 Views
Last Modified: 2008-02-26
Hi - could someone please advise how to open a URL from VBA within Word.

I can re-focus on an open Internet Explorer using AppActivate, but I want to open a fresh instance of Internet Explorer and navigate to a specific URL without any interaction by the user, ie: no hyperlink to click on or button to press etc.

Also, will the code someone lists work with both IE6 and the new IE7 or more specifically, Microsoft Internet Explorer and Windows Internet Explorer.

Many thanks.

Justin.
0
Comment
Question by:justinkent
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
Comment Utility
Greetings, justinkent.

The code below will create a new instance of Internet Explorer, navigate to the URL given, and then make the browser visible.  This works fine in IE6, not sure about IE7 as I don't have it loaded, but I'm pretty confident this'll work.  

Sub OpenIE()
    Const READYSTATE_COMPLETE = 4
    Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "http://www.yahoo.com"
    Do While objIE.readyState <> READYSTATE_COMPLETE
        DoEvents
    Loop
    objIE.Visible = True
    Set objIE = Nothing
End Sub

Cheers!
0
 

Author Comment

by:justinkent
Comment Utility
Perfect, thanks.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.
0

Featured Post

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.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

18 Experts available now in Live!

Get 1:1 Help Now