Hello,
I want to create bookmark in word document - when user selects the text, clicks mouse right button and chooses item form context menu (Add bookmark) the action for this click event fires such code:
Microsoft.Office.Interop.Word.
Range rng;Microsoft.Office.Interop.Word.
Bookmark bm;applicationObject.ActiveDocument.ActiveWindow.View.ShowBookmarks =
true;rng = applicationObject.ActiveDocument.Application.Selection.Range;
Object range = rng;bm = applicationObject.ActiveDocument.Bookmarks.Add(
"bm1", ref range);bm.Application.Selection.FormattedText.Font.Shading.BackgroundPatternColor = (Microsoft.Office.Interop.Word.
WdColor)System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(100, 24, 150));//Microsoft.Office.Interop.Word.WdColor.wdColorBrown;bm.Application.Selection.FormattedText.Font.Color = (Microsoft.Office.Interop.Word.
WdColor)System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(10, 240, 50));
It works fine as long as I am selecting text outside table (bookmark start and end markers are in a correct positions), but when I am selecting text that occupies more than one row, column or cell in a table the bookmark's range occupies much more cells (and text) that was selected. For example when I have such a table:
MIESI CZNE CENY PAKIETOW w PLN Komfortowy Cz onka. Rodziny Standardowy Komplekso-wy - - Diamentowy Brylantowy Pakiet Indywidualny - 15,00 * 35,00 * 160,00 *xxxxxxxx 260,00 * Pakiet dla jednego cz onka rodziny 40,00 * - - - - Pakiet Rodzinny (wspo ma onek/partner oraz dzieci) 55,00 * 75,00 * - - Wspo ma onek / Partner yciowy - - 160,00 * 200,00 * Dziecko (do 25r ) - - 120,00 * 160,00 * Rodzic - - 260,00 * 340,00 * Dwoje rodzicow - - 440,00 * 600,00 *
and I want to select cells marked orange (2 cells: Diamentowy + xxxxxx) in fact the code provided selects these cells + a few more (like Brylantowy, Pakiet indywidualny,....).
When I am creating this bookmark from the Word UI, it makes this bookmark ranges ok. Where could be the problem Some hints or code examples would be great.
Best Regards