L
lltaylor
Hello,
I have an application that I use to scan through some word documents.
I have successfully managed to get my app, to open the relevant
documents and usings Word's find function, find the relevant part.
However when it starts its search an instance of word opens up, and I
thought I had invoked a close but the application stays open.
How do I close word once it has been opened, or better still how do I
carry out my find with word not opening at all.
Thanks in advance...
Lloyd
Here is some of the code.
//Open File paramters
object filename;
object confirmConversions = Type.Missing;
object readOnly = true;
object addToRecentFiles = Type.Missing;
object passwordDocument = Type.Missing;
object passwordTemplate = Type.Missing;
object revert = Type.Missing;
object writePasswordDocument = Type.Missing;
object writePasswordTemplate = Type.Missing;
object format = Type.Missing;
object encoding = Type.Missing;
object visible = Type.Missing;
object openConflictDocument = Type.Missing;
object openAndRepair = Type.Missing;
object documentDirection = Type.Missing;
object noEncodingDialog = Type.Missing;
//Close File Paramters
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Type.Missing;
object routeDocument = Type.Missing;
My method which opens the relevant file, searches it and "closes" it.
public void MSWordSearch()
{
oWord = new Word.Application();
try
{
oWord.Documents.Open(ref filename, ref confirmConversions, ref
readOnly, ref addToRecentFiles, ref passwordDocument,
ref passwordTemplate, ref revert, ref writePasswordDocument, ref
writePasswordTemplate, ref format, ref encoding, ref
visible, ref openConflictDocument, ref openAndRepair, ref
documentDirection, ref noEncodingDialog);
oDoc = oWord.ActiveDocument;
int intFound = 0;
Word.Find fnd = oWord.Selection.Find;
fnd.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Word.WdFindWrap.wdFindContinue;
fnd.Text = matchPattern;
ExecuteFind(fnd);
while(fnd.Found)
{
intFound++;
ExecuteFind(fnd);
}
UIupdate(" *** " + intFound + " occurences of " + matchPattern + "
found in " +this.filename.ToString()+ "\n");
oWord.Documents.Close(ref saveChanges, ref originalFormat, ref
routeDocument);
}
catch(Exception ex)
{
UIupdate("Error occurred reading file " +this.filename.ToString()+ "
" + ex.ToString());
}
}
I have an application that I use to scan through some word documents.
I have successfully managed to get my app, to open the relevant
documents and usings Word's find function, find the relevant part.
However when it starts its search an instance of word opens up, and I
thought I had invoked a close but the application stays open.
How do I close word once it has been opened, or better still how do I
carry out my find with word not opening at all.
Thanks in advance...
Lloyd
Here is some of the code.
//Open File paramters
object filename;
object confirmConversions = Type.Missing;
object readOnly = true;
object addToRecentFiles = Type.Missing;
object passwordDocument = Type.Missing;
object passwordTemplate = Type.Missing;
object revert = Type.Missing;
object writePasswordDocument = Type.Missing;
object writePasswordTemplate = Type.Missing;
object format = Type.Missing;
object encoding = Type.Missing;
object visible = Type.Missing;
object openConflictDocument = Type.Missing;
object openAndRepair = Type.Missing;
object documentDirection = Type.Missing;
object noEncodingDialog = Type.Missing;
//Close File Paramters
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Type.Missing;
object routeDocument = Type.Missing;
My method which opens the relevant file, searches it and "closes" it.
public void MSWordSearch()
{
oWord = new Word.Application();
try
{
oWord.Documents.Open(ref filename, ref confirmConversions, ref
readOnly, ref addToRecentFiles, ref passwordDocument,
ref passwordTemplate, ref revert, ref writePasswordDocument, ref
writePasswordTemplate, ref format, ref encoding, ref
visible, ref openConflictDocument, ref openAndRepair, ref
documentDirection, ref noEncodingDialog);
oDoc = oWord.ActiveDocument;
int intFound = 0;
Word.Find fnd = oWord.Selection.Find;
fnd.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Word.WdFindWrap.wdFindContinue;
fnd.Text = matchPattern;
ExecuteFind(fnd);
while(fnd.Found)
{
intFound++;
ExecuteFind(fnd);
}
UIupdate(" *** " + intFound + " occurences of " + matchPattern + "
found in " +this.filename.ToString()+ "\n");
oWord.Documents.Close(ref saveChanges, ref originalFormat, ref
routeDocument);
}
catch(Exception ex)
{
UIupdate("Error occurred reading file " +this.filename.ToString()+ "
" + ex.ToString());
}
}