Opening an instance of Internet Explorer from Word macro?

R

Rob Meade

Hi all,

First please excuse cross post, I deemed it appropriate in this
circumstance - appologies for any offence.

Secondly...

I need to open an internet explorer window and fire it off to a specified
URL from a Word macro - thus far I have the button!

I have trawled the web and found little to nothing of use, I have spent the
morning looking at the Internet Explorer object model, and have just found
some info with the VB help - which - well - didn't help and the examples
errored...

If anyone could help me with this I would be most grateful.

Regards

Rob
 
J

Jonathan West

Hi Rob,

Go to http://www.mvps.org/vb/samples.htm, and download the HyperJmp.zip code
sample, and import the .bas module in that file into your project.

All you need to is call the routine passing it your URL, and the default
browser (Internet Explorer or whatever else that might be configured) is
opened at that page.
 
R

Rob Meade

...
Go to http://www.mvps.org/vb/samples.htm, and download the HyperJmp.zip code
sample, and import the .bas module in that file into your project.

All you need to is call the routine passing it your URL, and the default
browser (Internet Explorer or whatever else that might be configured) is
opened at that page.

Hi Jonathon,

Thank you for your reply. Since posting I did manage to trigger an instance
of Internet Explorer using the following :

Sub Upload()

Dim OpenerURL

OpenerURL =
"https://nww.avon.nhs.uk/cp/login.asp?URL=http://nww.avon.nhs.uk/cms/emergen
cyadmissions.asp&Res=10"

ActiveDocument.FollowHyperlink Address:=OpenerURL, NewWindow:=True,
AddHistory:=True


End Sub


However, I need to take this a bit further....

The Word macro that we have here at the NHS at the moment enables you to
click on a button for the hospital, enter a hospital number (patient number)
and both the GP and patient demographics are returned.

In turn this actually opens a new document *without* the macro or grey
fields on the page which is then ready for printing/saving etc, the previous
document remains unchanged so that they may create another.

What I've been asked to do is link from Word to a .net web application which
I have to write which will enable to the document to be storage in a central
respository.

I have managed thus far to add a button and direct the browser to the
address above - however - I need the querystring to be built up from the
data from the fields which were returned by the database call in the first
place.

I'm not sure how to ;

a) reference the fields on the template to extract data (made more complex
by the fact that the fields on the template never have a value, only the
ones which would have been there on the new document have the data - but
then are not fields - I think)...

Assuming I can do this I can then have a more dynamic querystring enabling
me to acces the application with some data...

example:

I return a patient number (field is called PNumber)

the URL would end up something like:

OpenerURL =
"https://nww.avon.nhs.uk/cp/login.asp?URL=http://nww.avon.nhs.uk/cds/default
..asp?pnumber=" & pNumber

That kinda thing....

If you have any ideas I would love to hear from ya, I cannot find ANYTHING
of use online at all and have no VBA experience, I come purely from a webby
background using primarily ASP - and just recently moving to .net (which
cant be used for the macro)...

Regards

Rob
 
J

Jonathan West

Rob Meade said:
...


Hi Jonathon,

Thank you for your reply. Since posting I did manage to trigger an instance
of Internet Explorer using the following :

Sub Upload()

Dim OpenerURL

OpenerURL =
"https://nww.avon.nhs.uk/cp/login.asp?URL=http://nww.avon.nhs.uk/cms/emergen
cyadmissions.asp&Res=10"

ActiveDocument.FollowHyperlink Address:=OpenerURL, NewWindow:=True,
AddHistory:=True


End Sub

Beware. The FollowHyperlink method causes an error if you don't have a
document open for editing.
However, I need to take this a bit further....

The Word macro that we have here at the NHS at the moment enables you to
click on a button for the hospital, enter a hospital number (patient number)
and both the GP and patient demographics are returned.

In turn this actually opens a new document *without* the macro or grey
fields on the page which is then ready for printing/saving etc, the previous
document remains unchanged so that they may create another.

What I've been asked to do is link from Word to a .net web application which
I have to write which will enable to the document to be storage in a central
respository.

I have managed thus far to add a button and direct the browser to the
address above - however - I need the querystring to be built up from the
data from the fields which were returned by the database call in the first
place.

I'm not sure how to ;

a) reference the fields on the template to extract data (made more complex
by the fact that the fields on the template never have a value, only the
ones which would have been there on the new document have the data - but
then are not fields - I think)...

From your description, I'm not 100% sure what you are trying to achieve, but
since it is to do with getting data into and out of forms in Word, this
series of articles by Dian Chapman should be useful

http://www.computorcompanion.com/LPMArticle.asp?ID=22
Part 1: Learn to create professional looking forms in Word.
by Dian Chapman
[Copyright (c) Logical Expressions, Inc.]
http://www.computorcompanion.com/LPMArticle.asp?ID=46
Part 2: Add Automation to your Word forms.
by Dian Chapman
[Copyright (c) Logical Expressions, Inc.]

http://www.computorcompanion.com/LPMArticle.asp?ID=119
Part 3: Learn more VBA (macros) to automate your forms.
by Dian Chapman
[Copyright (c) Logical Expressions, Inc.]

http://www.computorcompanion.com/LPMArticle.asp?ID=127
Part 4: Lean how to use dialog boxes in your Word forms.
by Dian Chapman
[Copyright (c) Logical Expressions, Inc.]

http://www.computorcompanion.com/LPMArticle.asp?ID=136
Part 5: Connect your AutoForm to a database to save input time and keep
better records!
by Dian Chapman
[Copyright (c) Logical Expressions, Inc.]


Assuming I can do this I can then have a more dynamic querystring enabling
me to acces the application with some data...

example:

I return a patient number (field is called PNumber)

the URL would end up something like:

OpenerURL =
"https://nww.avon.nhs.uk/cp/login.asp?URL=http://nww.avon.nhs.uk/cds/default
.asp?pnumber=" & pNumber

That kinda thing....

Building a querystring should be no problem. What might be more of an issue
is getting the relevent data back into your document. Simply opening the
browser at the correct page isn't of itself going to be enough, as far as I
can see.

What it seems that you need to do is to be able to download the returned
data into a string or file which you can then manipulate in any way you
need. For this, go to http://www.mvps.org/vb/samples.htm, and scroll down
the the Slurp.zip sample.


If you have any ideas I would love to hear from ya, I cannot find ANYTHING
of use online at all and have no VBA experience, I come purely from a webby
background using primarily ASP - and just recently moving to .net (which
cant be used for the macro)...

Take a good look at http://word.mvps.org, it has lots of Word VBA code
samples.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top