Hi,
I get the feeling this is a dumb question, but I am trying to run a mailmerge with word from an ASP.NET (
VB) web page. I have created a text file that holds the merge data and I have a master document located on the local drive of the user (the text file is saved there as well).
As I am just setting out I am using Web Matrix as development environment. Also I am not splitting out the
vb into a code behind page at the moment. It's all contained in the .aspx file.
When I load the page using the Web Matrix web server it works fine. The text file is created and Word launches and does the mail merge. If, however I launch the page using IIS, all works ok, except I can't get word to display. I have looked at task manager and the ASP.NET user has launched a Word process, the two files (.txt and .doc) are locked, but Word is not displayed.
Can anyone help? I have the code below:
==== CODE START ====
<%@ Page Language="
VB" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
Dim strData As String
strData = "FirstName,Surname,Address,City,County,PostCod e" & vbCrLf
strData = StrData & "Andy,Parker,93 Bushy Hill Drive,Guildford,Surrey,GU1 2UG" & vbCrLf
strData = StrData & "Allison,Goody,7 Smith Road,Guildford,Surrey,GU4 4QY" & vbCrLf
strData = StrData & "John,Smith,45 Red Road,Guildford,,GU4 4QY"
Dim ExportFileName As string
Dim MasterDocName As String
ExportFileNAme = "C:\TDD\Templates\Andy.txt"
MasterDocName = "C:\TDD\Templates\Test.doc"
If File.Exists(ExportFileName) Then
File.Delete(ExportFileName)
End If
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(ExportFileName)
objStreamWriter.WriteLine(strData)
objStreamWriter.Close
Dim objWord As Object
Dim objDoc As Object
objWord = CreateObject("Word.Application")
objDoc = objWord.Documents.Open(MasterDocName)
objWord.Visible = True
With objWord.ActiveDocument.MailMerge
.OpenDataSource(ExportFileName)
.SuppressBlankLines = True
.Execute
End With
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Create Label"></asp:Button>
</p>
</form>
</body>
</html>
==== CODE END ====
Thanks
Andy