amccorma

I have references to Microsoft.Office.Core and Microsoft.Office.Interop.Word.

Microsoft.Office.Core: 2.2.0.0

Microsoft.Office.Interop.Word; 8.4.0.0

I have googled and searched the forums I am stuck and have no idea why this is failing. The directory has read/write permissions for the Network Service Account. I am tying to run a find and replace in a word document from asp.net.

My code:

object missing = System.Reflection.Missing.Value;

oWordApplic.Visible = false;

Microsoft.Office.Interop.Word.Range range = oWordApplic.ActiveDocument.Content;

//oWordApplic.Selection.Find.ClearFormatting();

//Microsoft.Office.Interop.Word.Selection sel = oWordApplic.Selection;

object findtext = Source;

object f = false;

object findreplacement = "NewString";

object findforward = false;

object findformat = true;

object findwrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

object findmatchcase = false;

object findmatchwholeword = false;

object findmatchwildcards = false;

object findmatchsoundslike =false;

object findmatchallwordforms = false;

object findreplace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;

range.Find.Execute(ref findtext,ref findmatchcase,ref findmatchwholeword,

ref findmatchwildcards,

ref findmatchsoundslike, ref findmatchallwordforms, ref findforward,

ref findwrap, ref findformat, ref findreplacement, ref findreplace, ref missing, ref missing,

ref missing,

ref missing);

My error:

System.Runtime.InteropServices.COMException (0x800706F7): The stub received bad data. (Exception from HRESULT: 0x800706F7) at Microsoft.Office.Interop.Word.Find.Execute(Object& FindText, Object& MatchCase, Object& MatchWholeWord, Object& MatchWildcards, Object& MatchSoundsLike, Object& MatchAllWordForms, Object& Forward, Object& Wrap, Object& Format, Object& ReplaceWith, Object& Replace, Object& MatchKashida, Object& MatchDiacritics, Object& MatchAlefHamza, Object& MatchControl) at WordApplication.CCWordApp.FindAndReplace(String Source, String NewString) in C:\Documents and Settings\amccormack\Desktop\WordApplication_demo\WordApplication\CCWordApp.cs:line 117 at WordApplication.ModifyDocument.Button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\amccormack\Desktop\WordApplication_demo\WordApplication\ModifyDocument.aspx.cs:line 71

Anyone know what is going on Thanks

Andrew



Re: Visual Studio Tools for Office C# find and replace in Word

Ji Zhou ¨C MSFT

Hi Andrew,

First, this issue is off topic in the VSTO forum. The right place for it should be Word general news group, here:

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.word.vba.general&lang=en&cr=US

Your code looks all right. I copy it into a Winform project, and it runs fine. I notice that, from the call stack you post, you are working on an ASP.NET Web Application project.

From Microsoft KB article 897662, you will see that, if we run COM server-side or client-side programs on a Windows XP SP2 machine, we may suffer from the error: ¡°The stub received bad data.¡±

There is a supported hotfix already. You can get it following the KB article.

http://support.microsoft.com/KB/897662

Hope this helps!

Thanks

Ji






Re: Visual Studio Tools for Office C# find and replace in Word

Cindy Meister

I've mentioned this quite a number of times, in the forums and newsgroups, but once again:

If you're getting a crash when using the Find object while automating Word, the most likely cause is what's described in this KB article

http://support.microsoft.com/default.aspx scid=kb;en-us;313104






Re: Visual Studio Tools for Office C# find and replace in Word

amccorma

Thanks. I did search the forums for word and did not find any results for this. maybe my search was wrong. It works now.