Opening a URL in Word through Automation

K

Kevin

I have some VBScript that passes a URL to Word via OLE Automation. The
URL (http://TestDomain/WordTest/test.asp) points to a site using Basic
Authentication as the authentication method. Word generates the
following error on the Open method of the Documents object,

The document name or path is not valid. Try one or more of the
following:
* Check the path to make sure it was typed correctly.
* On the File menu, click Open. Search for the file using this dialog
box. (http://TestDomain/../test.asp)

However, if I open the same URL through Word's File Open dialog, Word
will generate a dialog requesting user credentials and successfully
load the page. There's no problem if the authentication method is
anonymous access. Also, Word will successfully load the page without a
dialog if the user's credentials are also sent along with the URL in
the following format:
(http://username:password@@TestDomain/WordTest/test.asp).
Unfortunately, passing the username and password in the URL is not an
acceptable solution.

Any ideas on why Word won't throw a dialog through automation on sites
using Basic Authentication? I'm using Word XP on Win 2K SP3.


VBScript code:

Dim oWord
Dim i

On Error Resume Next
Set oWord = CreateObject("Word.Application")
If Err.Number = 0 Then
With oWord
.Visible = True
.Documents.Open "http://TestDomain/WordTest/test.asp"

If Err.Number <> 0 Then
MsgBox "Err.Number = " & Err.number & vbCrLf & _
"Err.Source = " & Err.Source & vbcrlf & _
"Err.Description = " & Err.Description
Else
For i = .ActiveDocument.Hyperlinks.Count to 1 Step -1
.ActiveDocument.Hyperlinks(i).Delete
Next

.ActiveWindow.View.TableGridlines = False

Msgbox "Test", vbInformation, "Test"
End If
End With
End If

Set oWord = Nothing

ASP page code:
<%

response.write "<html><head><title>Testing
Word</title></head><body><H1>Hello World</H1></body></html>"

%>
 
C

Cindy Meister -WordMVP-

Hi Kevin,

Well, the .Open method simply isn't the equivalent of what the dialog
box is capable of. It has a very specific purpose, and no arguments to
accomodate what you're trying to do.

My suggestion would be to try using the dialog box. In VBA-speak:

Set dlg = wdApp.Dialogs(wdDialogFileOpen)
with dlg
.Name = "http://etc."
.Execute
End With

Should display the dialog box for the user credentials.
I have some VBScript that passes a URL to Word via OLE Automation. The
URL (http://TestDomain/WordTest/test.asp) points to a site using Basic
Authentication as the authentication method. Word generates the
following error on the Open method of the Documents object,

The document name or path is not valid. Try one or more of the
following:
* Check the path to make sure it was typed correctly.
* On the File menu, click Open. Search for the file using this dialog
box. (http://TestDomain/../test.asp)

However, if I open the same URL through Word's File Open dialog, Word
will generate a dialog requesting user credentials and successfully
load the page. There's no problem if the authentication method is
anonymous access. Also, Word will successfully load the page without a
dialog if the user's credentials are also sent along with the URL in
the following format:
(http://username:password@@TestDomain/WordTest/test.asp).
Unfortunately, passing the username and password in the URL is not an
acceptable solution.

Any ideas on why Word won't throw a dialog through automation on sites
using Basic Authentication? I'm using Word XP on Win 2K SP3.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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