Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX error when creating Word object

Status
Not open for further replies.

wtstro

Programmer
Aug 1, 2002
15
US
Not sure if this should go in ASP.NET or VB.NET so I am placing it in both.

I am creating a web page that takes information from a form and populates "bookmarks" in a Word template.

The process works great during VS debug on my localhost, but when I try to run it on the server I get the error: "Cannot create ActiveX component".

The code that instantiates the Word object, opens the template, and populates the document resides in the codebehind file.

A thought that came to mind was: Is .NET trying to use Word from the server or from the user's workstation? If the server, how do I get it to use Word installed on the user's workstation instead?

Here is my code:

Dim objWord As Word.Application

objWord = CreateObject("Word.Application")

With objWord
.ActivePrinter = "Lexmark 2200"
.Visible = True
.WindowState = Word.WdWindowState.wdWindowStateMinimize
.Documents.Open(Server.MapPath("\includes") + "\ltrWelcome.dot")

.ActiveDocument.Bookmarks.Item("txtDate").Select()
.Selection.Text = Now()
.ActiveDocument.Bookmarks.Item("txtUserName").Select()
.Selection.Text = txtUserName.Text

.PrintOut(Copies:=1, Collate:=True, Background:=True, PrintToFile:=False)

'Wait for document to print
Do While .BackgroundPrintingStatus > 0
'Loop until document printed then continue
Loop

.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
.Quit()
End With

Thanks.
 
Is .NET trying to use Word from the server or from the user's workstation?

Yes.

If the server, how do I get it to use Word installed on the user's workstation instead?

You don't. ADO.Net runs entirely server side, all that goes back and forth is HTML. You may be able to use some kind of active-x control to embed a word document on the web page, that should use the client's copy of word, but you won't be able to use .Net to alter the doc on their end.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
havin a bad hair day Rick?

Is .NET trying to use Word from the server or from the user's workstation?

is not a yes/no question.

You don't. ADO.Net runs entirely server side,

He is talking ASP.NET

Allthough what ricks says is correct. But I would still go to the asp.net forum and ask if somebody has an answer. I still think the word document would open. I'mm just not sure th activeprinter thingie will work.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top