By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

missing code in Word Index

P: n/a
hi can any one help me out,
i have written a code for Word Indexing using Dll's
i think this is an incomplete code for WORD INDEX.

I had encountered this error
"Error! No index entries found" when i opened word document

can any one fill out the missing code with this.


public static void Index(string filePath)
{
try
{
Word.Application wordApp = new Word.Application();
Word.Documents docs = wordApp.Documents;

object filePathName = filePath;
object missing = Type.Missing;
object saveChanges = "true";

Word.Document doc= docs.Open(ref filePathName,
ref missing, // confirmconversions,
ref missing, // readOnly,
ref missing, // addtoRecentFiles,
ref missing, // passworddOc,
ref missing, // passwdTemplate,
ref missing, // revert,
ref missing, // writePasswordDoc,
ref missing, // writePasswordTemplate,
ref missing, // format,
ref missing, // encoding,
ref missing // visible,
);

//wordApp.Visible = true;
object end = "\\endofdoc";

//indexes of the object
object endLocation = doc.Content.End;
object startLocation = doc.Content.Start;
Word.Range rng = doc.Range(ref startLocation, ref endLocation);

doc.Indexes.Add(rng,
ref missing, // HeadingSeparator
ref missing, // RightAlignedPageNumber
ref missing, // object Type
ref missing, // NumberOfColumns
ref missing, // AccentedLetters
ref missing, // Sort By
ref missing // IndexLanguage
);
// Adding a Index to Indexes
object Entry = "Comments" ;
object CrossReference = "Comments" ;
object BookmarkName = "Comments" ;
object Bold = "True" ;
doc.Indexes.MarkEntry(rng,
ref Entry,
ref missing, //EntryAutoText
ref missing, //CrossReference
ref CrossReference, // CrossReferenceAuoText
ref BookmarkName,//BookmarkName
ref missing, // Bold
ref missing, // Italic
ref missing // Reading
);
Word.Index.

wordApp.Selection.GoTo(ref missing,ref missing,ref missing ,ref end);
object type=2;
wordApp.Documents.Save(ref missing,ref missing);
wordApp.Documents.Close(ref missing,ref missing,ref missing);
wordApp.Quit(ref missing, ref missing, ref missing);
}

catch(Exception ex)
{
MessageBox.Show("Converted documents into the Existing Document."+ex);
}
}
}
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.