T
tyla
I'm having trouble done a simple "Find" against a Word document. Seems
it should be simple from all the various UseNet messages and MSDN
postings, but it's failing here for reasons that must be so obvious I'm
missing them entirely.
Let's assume a Word 2003 document with two simple sentences in it, the
first one containing the word "jump". Here's my boiled down code:
// =============
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.Text;
namespace whatever
{
class Program
{
static void Main(string[] args)
{
Word.Application wordApp = new Word.Application();
wordApp.Visible = true;
try
{
object missing = Type.Missing;
object sFileName = @"C:\Temp\jump.doc";
Word.Document wordDoc = wordApp.Documents.Open(ref
sFileName,
ref missing, ref missing, ref
missing, ref missing, ref missing,
ref missing, ref missing, ref
missing, ref missing, ref missing,
ref missing, ref missing, ref
missing, ref missing, ref missing);
Word.Range rng = wordDoc.Sentences[1];
Console.WriteLine(rng.Sentences.Count.ToString());
object s = "jump";
if (rng.Find.Execute(ref s, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing) )
{
MessageBox.Show("Yup!");
}
else
{
MessageBox.Show("Nope!");
}
}
catch (Exception ex)
{
Console.WriteLine("+++++++++++++++");
Console.WriteLine(ex.ToString());
Console.WriteLine("+++++++++++++++");
MessageBox.Show("No way, Jose");
}
finally
{
MessageBox.Show("Done!");
}
}
}
}
==============
It consistently throws an Exception on the "Find.Execute" line for
reasons unknown. The ex.ToString() reads:
"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 whatever.Program.Main(String[] args) in
C:\UDApps\ConsoleApplication5\ConsoleApplication5\Program.cs:line xx"
which, somehow, isn't terribly informative to this hacker. Any help
here would be very much appreciated.
= Tyla =
it should be simple from all the various UseNet messages and MSDN
postings, but it's failing here for reasons that must be so obvious I'm
missing them entirely.
Let's assume a Word 2003 document with two simple sentences in it, the
first one containing the word "jump". Here's my boiled down code:
// =============
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.Text;
namespace whatever
{
class Program
{
static void Main(string[] args)
{
Word.Application wordApp = new Word.Application();
wordApp.Visible = true;
try
{
object missing = Type.Missing;
object sFileName = @"C:\Temp\jump.doc";
Word.Document wordDoc = wordApp.Documents.Open(ref
sFileName,
ref missing, ref missing, ref
missing, ref missing, ref missing,
ref missing, ref missing, ref
missing, ref missing, ref missing,
ref missing, ref missing, ref
missing, ref missing, ref missing);
Word.Range rng = wordDoc.Sentences[1];
Console.WriteLine(rng.Sentences.Count.ToString());
object s = "jump";
if (rng.Find.Execute(ref s, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing) )
{
MessageBox.Show("Yup!");
}
else
{
MessageBox.Show("Nope!");
}
}
catch (Exception ex)
{
Console.WriteLine("+++++++++++++++");
Console.WriteLine(ex.ToString());
Console.WriteLine("+++++++++++++++");
MessageBox.Show("No way, Jose");
}
finally
{
MessageBox.Show("Done!");
}
}
}
}
==============
It consistently throws an Exception on the "Find.Execute" line for
reasons unknown. The ex.ToString() reads:
"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 whatever.Program.Main(String[] args) in
C:\UDApps\ConsoleApplication5\ConsoleApplication5\Program.cs:line xx"
which, somehow, isn't terribly informative to this hacker. Any help
here would be very much appreciated.
= Tyla =