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.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top