ASP.NET and MS Word Find and Replace Error

J

Jordan

Hi. I am autoamtiacally creating a MS Word file through code. Most of
my code works, but when I try to do a find and replace, I get a
read/write memrory access error. Not sure what is going on. Any advice?
Error occurs on the .Text line of the with block

Public wordapp As New Microsoft.Office.Interop.Word.Application
Public doc As New Microsoft.Office.Interop.Word.Document

With wordapp.Selection.Find
.Text = "[" & Trim(strField) & "]"
.Replacement.Text = Trim(strReplacementText)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wordapp.Selection.Find.Execute(Replace:=wdReplaceAll)
 
M

Mark Rae

Hi. I am autoamtiacally creating a MS Word file through code.
Public wordapp As New Microsoft.Office.Interop.Word.Application
Public doc As New Microsoft.Office.Interop.Word.Document

You would be strongly advised NOT to do this due to stability, performance
and scalability issues.

In fact, Microsoft themselves strongly advise against doing this and,
furthermore, will not support any application which does this:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Creating a Word file in ASP.NET without automation is not particularly
difficult - choose one of the following options instead:

1) Create an HTML file and give it a .doc extension.

2) Create an XML Word file and give it a .doc extension - the XML schema for
Word (and other Office products) is readily available on the web

3) Use a 3rd-party product like this:
http://www.aspose.com/Products/Aspose.Words/Default.aspx - while you're
there, click in the "Why Not Automation?" hyperlink...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top