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());
}
} 8 2771
Lloyd,
try adding:
oWord.visible = false;
to MSWordSearch. You cannot close word (or dispose of the object) as
this stores the Find method you need to use, and also is the parent
class for your Word Document objects. But hide it using the above
property, and you wont know its there...
Nick
Thanks,
That certainly helped....however word still appears briefly in the
status bar, causing a flicker like effect.
Is there anyway round that?
This is the order I have my code
oWord = new Word.Application();
oWord.Visible = false;
oWord.Documents.Open(.................);
Any ideas.
Lloyd
*** Sent via Developersdex http://www.developersdex.com ***
Lloyd,
What version of Office do you have? I have 2003, and my Word object is
visible by default, so I dont get the flicker.
The only way I can think to get around that for you, is to use the
'LockWindowUpdate' API call. This sends a message to windows to freeze
screen painting, so you could call this before creating oWord, set to
visible then turn unlock window updates (by calling the same api with a
value of 0).
Very messy, but your only solution I think...
Nick
oops...too early, and not enough caffeine....
I meant to say:
"and my Word object is INvisible by default, so I dont get the flicker."
Thanks Nick,
I am using Office 2003 too, how to you set your Word object to be
invisible by default?
Lloyd
*** Sent via Developersdex http://www.developersdex.com ***
thats the weird thing, I didnt need to. and Ive got no idea why the
behaviour is different on my machine to yours...
Stupid question, but did you declare oWord as Word.Application? Its
not in the sample you posted...
These are just code snippets as that actual class is quite long.
Most of the arguments for the Open Method are of Type.Missing;
Everything works perfect, just that I get an annoying flicker everytime
word opens up and as the actual app is scanning a directory it can be a
little annoying.
I appreciate all your help though.
-------My Code--------
using Microsoft.Office.Core;
using System.Reflection;
Word.Application oWord;
Word.Document oDoc;
oWord = new Word.Application();
oWord.Visible = false;
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;
Word.Find fnd = oWord.Selection.Find;
And so on.........
*** Sent via Developersdex http://www.developersdex.com ***
Final thought, maybe its an OS thing? Im running XP SP2, maybe you
have win2k? long shot, but your code behaves itself on my machine...or
maybe there is something screwy with the install of Office...
Check this thread too Lloyd: http://tinyurl.com/9f8s4 , could be
something to do with the normal.dot (word template) you have? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mickeydisn |
last post by:
Sub: C++ Word automation Extract text
hello.
I want extact text form a word document using a visual c++ programme.
I have see a lot of documentation. and my analysis is that I must use a...
|
by: Mike MacSween |
last post by:
Office 2000
From Access I've been starting an instance of word and doing a mail merge.
Everything hunky-dory until I applied SP1 yesterday.
Now this:
dim wrd as Object
set wrd =...
|
by: Cheval |
last post by:
Has anyone had any problems with inter-office automation between MS Word and
MS Access in Office 2003?
I have recently installed office 2003 in a new folder and have left the
older office 2000...
|
by: kids |
last post by:
Does anybody know any reason which could cause Ms. word automation to crash?
I try to call word automation to open a document and use find and replace
function.
For some reason it works but I...
|
by: Daniel |
last post by:
Hello,
i have a problem with the word automation from c#. First,
i want to mention, that i don't have any dependencies from
word in my c#-project, i want to use the system.reflection
model to...
|
by: mharris |
last post by:
I need help with merging two Word documents into one through C#
code. The problem isn't so much getting the documents put into one as
it is maintaining the appropriate formatting, or rather...
|
by: Radek |
last post by:
Hi, I have got such problem:
in my directory "C:\folder" I have 3 files in MS WORD (having tables, images
etc), these are:
"1.doc", "2.doc", "3.doc".
I want to write an application (C# of...
|
by: Daniel Walzenbach |
last post by:
Hi,
I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be...
|
by: liya.tansky |
last post by:
Hello,
I'm developing an intranet (win XP, .NET 2, Visual Studio 2005,
Microsoft.Office.Interop.Word.dll in references) and needed to
implement find-replace in word doc before sending letter and...
|
by: apondu |
last post by:
Hi,
can someone help me and provide me the information on how to supress
the
default action of the shortcut keys of word during word automation.
I am using C#.Net
I have written a code but...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |