Problem with ActiveDocument when using Word in ASP.Net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All,

I'm using a word application in ASP.net (server side) to open an existing
document, do a mail merge on it and then serve the created document to the
client.

The problem I am having is when I open the word document using the
Word.Application and I then try to access the ActiveDocument property I get
an error message saying that 'This command is not available because no
document is open. '

I have tried the exact same code in Windows forms and it works fine.

The code is;
Dim wordDoc As Word.Document
Dim wordApp As New Word.Application

fileName = "c:\killian.doc"

'
----------------------------------------------------------------
wordDoc = wordApp.Documents.Open(fileName, missing, [readOnly],
missing, missing, missing, missing, missing, missing, missing, missing,
isVisible)

With wordApp.Application
.ActiveDocument.MailMerge.MainDocumentType = wdFormLetters

The code fails here with the error 'This command is not available because no
document is open. '

I can't figure out why this wont work. Thanks in advance for any help.

Killian
 
Hi,

From the top of my head - it may be that (1)there are not enough rights to
open the file or (2)the file is already opened in another instance or that
(3)there is some dialog box shown (which you have no way to see) and the
file isn't in fact opened. Try setting Application.DisplayAlerts to false to
prevent (3) at least.

Greetings
Martin
 
Back
Top