How do I select all text and change the text color with c#?

V

vincent

I want to select all the text in the documet and change it color before I
save the document.
How to do that?
Thank you for your replying.

WORD._Application word = null;
WORD._Document document = null;
Object fileName = (Object)tagetFileName;

try
{
word = new WORD.Application();

document = word.Documents.Add(
/* ref object Template */ ref word2jpgTemplate,
/* ref object NewTemplate */ ref missing,
/* ref object DocumentType */ ref missing,
/* ref object Visible */ ref missing);

//document.PageSetup.PageHeight = 999;
//document.PageSetup.PageWidth = 999;

//document.PageSetup.BottomMargin = 0;
//document.PageSetup.TopMargin = 0;
//document.PageSetup.LeftMargin = 0;
//document.PageSetup.RightMargin = 0;


document.SaveAs(
/* ref object FileName */ ref fileName,
/* ref object FileFormat */ ref fileFormat,
/* ref object LockComments */ ref missing,
/* ref object Password */ ref missing,
/* ref object AddToRecentFiles */ ref missing,
/* ref object WritePassword */ ref missing,
/* ref object ReadOnlyRecommended */ ref missing,
/* ref object EmbedTrueTypeFonts */ ref missing,
/* ref object SaveNativePictureFormat */ ref missing,
/* ref object SaveFormsData */ ref missing,
/* ref object SaveAsAOCELetter */ ref missing,
/* ref object Encoding */ ref missing,
/* ref object InsertLineBreaks */ ref missing,
/* ref object AllowSubstitutions */ ref missing,
/* ref object LineEncoding */ ref missing,
/* ref object AddBiDiMarks */ ref missing);
}
catch (COMException exception)
{
Console.WriteLine(exception.ToString());
}
finally
{
if (document != null)
{
document.Close(
/* ref object SaveChanges */ ref missing,
/* ref object OriginalFormat */ ref missing,
/* ref object RouteDocument */ ref missing);
document = null;
}

if (word != null)
{
word.Quit(
/* ref object SaveChanges */ ref missing,
/* ref object OriginalFormat */ ref missing,
/* ref object RouteDocument */ ref missing);
word = null;
}
}

GC.Collect();
GC.WaitForPendingFinalizers();

GC.Collect();
GC.WaitForPendingFinalizers();
 
D

Doug Robbins - Word MVP

I don't know anything about c#, but looking at the code you supplied, I
would suggest

//document.Range.Font.Color = wdColorRed

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

Cindy M.

Hi Vincent,
I want to select all the text in the documet and change it color before I
save the document.
Doug's on the right track, but the code he gave you won't convert directly
to C#. You need to do it more like this:

WORD.Range rng = document.Content;
rng.Font.Color = WORD.WdColor.wdColorRed;

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top