Similar Threads
1. Word late binding remove hidden text
Hello,
I want to remove the hidden text from a Word document and i have to
use late binding.
Tried early binding but that caused errors in Office 2007 (some error
about trying to write to protected memory).
So now I'm trying to do the same thing with late binding. I have no
problem opening the Word document and even
the Find works properly but when I try to remove hidden text it does
not seem to work.
Early binding code:
bool bShowHidden = wApp.ActiveWindow.View.ShowHiddenText;
wApp.ActiveWindow.View.ShowHiddenText = true;
Word.Find findObject = wApp.Selection.Find;
findObject.ClearFormatting();
findObject.Font.Hidden = 1;
findObject.Replacement.ClearFormatting();
findObject.Text = "";
findObject.Replacement.Text = "";
findObject.Forward = true;
findObject.Wrap = Word.WdFindWrap.wdFindContinue;
findObject.Format = true;
findObject.MatchCase = false;
findObject.MatchWholeWord = false;
findObject.MatchWildcards = false;
findObject.MatchSoundsLike = false;
findObject.MatchAllWordForms = false;
object replaceAll = Word.WdReplace.wdReplaceAll;
findObject.Execute(ref missing, ref missing, ref missing,
ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing,
ref replaceAll, ref missing, ref
missing, ref missing, ref missing);
foreach (Microsoft.Office.Interop.Word.Table myTable in
wApp.ActiveDocument.Tables)
{
if ((myTable.Range.Font.Hidden == 1) ||
(myTable.Range.Font.Hidden == -1))
{
myTable.Delete();
}
}
wApp.ActiveWindow.View.ShowHiddenText = bShowHidden;
late binding code:
Object ActiveWindow = wApp.GetType().InvokeMember("ActiveWindow",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.GetProperty, null, wApp, null);
Object View = ActiveWindow.GetType().InvokeMember("View",
System.Reflection.BindingFlags.GetProperty, null, ActiveWindow, null);
Object[] ShowHiddenTextParameter = new Object[1];
ShowHiddenTextParameter[0] = true;
Object ShowHidden = View.GetType().InvokeMember("ShowHiddenText",
System.Reflection.BindingFlags.GetProperty, null, View, null);
View.GetType().InvokeMember("ShowHiddenText",
System.Reflection.BindingFlags.SetProperty, null, View,
ShowHiddenTextParameter);
Object Selection = ActiveWindow.GetType
().InvokeMember("Selection",
System.Reflection.BindingFlags.GetProperty, null, ActiveWindow, null);
Object Find = Selection.GetType().InvokeMember
("Find", System.Reflection.BindingFlags.GetProperty, null, Selection,
null);
Find.GetType().InvokeMember("ClearFormatting",
System.Reflection.BindingFlags.InvokeMethod, null, Find, null);
Object Font = Find.GetType().InvokeMember
("Font", System.Reflection.BindingFlags.GetProperty, null, Find,
null);
Object[] FontParameter = new Object[1];
FontParameter[0] = 1;
Font.GetType().InvokeMember("Hidden",
System.Reflection.BindingFlags.SetProperty, null, Font,
FontParameter);
Object Hidden = Font.GetType().InvokeMember
("Hidden", System.Reflection.BindingFlags.GetProperty, null, Font,
null);
Object Replacement = Find.GetType
().InvokeMember("Replacement",
System.Reflection.BindingFlags.GetProperty, null, Find, null);
Replacement.GetType().InvokeMember
("ClearFormatting", System.Reflection.BindingFlags.InvokeMethod, null,
Replacement, null);
object[] _parameters;
_parameters = new object[15];
_parameters[0] = "";
_parameters[1] = false;
_parameters[2] = false;
_parameters[3] = false;
_parameters[4] = false;
_parameters[5] = false;
_parameters[6] = true;
_parameters[7] =
Word.WdFindWrap.wdFindContinue;
_parameters[8] = false;
_parameters[9] = "";
_parameters[10] = Word.WdReplace.wdReplaceAll;
_parameters[11] = false;
_parameters[12] = false;
_parameters[13] = false;
_parameters[14] = false;
Find.GetType().InvokeMember("Execute",
System.Reflection.BindingFlags.InvokeMethod, null, Find,
_parameters);
Object[] ShowHiddenTextParameter2 = new Object
[1];
ShowHiddenTextParameter2[0] = ShowHidden;
View.GetType().InvokeMember("ShowHiddenText",
System.Reflection.BindingFlags.SetProperty, null, View,
ShowHiddenTextParameter2);
So what am i doing wrong here? If i just find in a word in the search
it works but I want to remove the hidden text.
2. [C#, Word late binding] Next cell (MoveRight) - CSharp/C#
3. Late binding of COM events (Word)
Hi,
I'm currently developing a C# project using late binding to integrate with
different versions of Word. I'm calling methods and properties like this:
object documents = wordApplication.GetType().InvokeMember("Documents",
BindingFlags.GetProperty, null, wordApplication, null);
object wordDocument = documents.GetType().InvokeMember( "Open",
BindingFlags.InvokeMethod, null, documents, new object[12] { filename,
...... } );
My problem is that do want do do som stuff using Word's Quit event, but I
dont know how to do this using late binding? Can anyone provide me with som
sample code?
Kind Regards,
Sune
4. Late Bound Access to NormalTemplate.Saved property in Word (C#)
5. C# late binding for accessing WORD object model
I am attempting to use late binding to interface with word (versions
97, 2000 and 2002). I have a few questions:
1. How do I detect if there is an instance of word that I can attach
to rather than starting a new instance.
2. How can I determine which version of Word is running. (I assume I
need this as there may be instances where the arguments to methods
change from version to version).
3. Does the MailMerge facility exist in Office 97.
4. Does anyone know of any C# samples that run on Word 97, 2000 and
2002.
5. Where can I get acces to the word object model for all of these
versions of word.
6. Below is sample code that creates an instance of word and then
opens a document. To access the Open method on the Documents, I have
to somehow get a Type from an object. I achieve this by calling
Type.GetHandle and then call Type.GetTypeFromHandle. My instinct was a
GetTypeFromObject method but none exists. Is this the best way to do
this as it seems very messy?
Type t = Type.GetTypeFromProgID("Word.Application");
object w = Activator.CreateInstance(t);
object docs = t.InvokeMember("Documents", BindingFlags.GetProperty,
null, w, null);
// Get a type from an object???????
RuntimeTypeHandle handle = Type.GetTypeHandle(docs);
Type tDocs = Type.GetTypeFromHandle(handle);
object doc = tDocs.InvokeMember("Open", BindingFlags.InvokeMethod,
null, docs, new Object[] {@"C:\logfile.txt"});
6. late binding Word enumeration like WdSaveFormat.wdFormatWebArchive - CSharp/C#
7. Word automation and late/early binding
We are developing a C# application that has many interfaces to the
Microsoft suite (eg Word, Excel, Outlook, Powerpoint, etc). We need to
support Office 97, 2000, 2002 and any future versions.
Our first cut used early binding and worked fine with Office 2002. We
then ran on a machine that had Office 2000 installed and it all turned
to custard.
There appears to be a number of options to take to support multiple
versions:
(1) Use early binding on the lowest common demoninator (in our case
office 97)
(2) Use early binding for each office version (ie in our case, have
three different assemblies for 97, 2000 and 2002)
(3) Use late binding
We would prefer to go with Option (1) as this means no code changes
(not yet clarified). However, we are not convinced that this is the
correct thing to do.
What do others think?
8. Editing bookmarks in Word using late binding - CSharp/C#