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.
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.