none
manipulating the cursor RRS feed

  • Question

  • Hi,

    I have code here in Inserting Citation and Bibliography but I'm having a problem when I insert a citation the second time

    first time I insert a citation

    (citaiton1)

    (all bibliography)

    but when I insert a citation the second time the problem occur 

    (citaiton1)

    (all bibliography)

    (citaiton2)

    and what I want is it will do like this

    (citaiton1)(citaiton2)

    (all bibliography)

    I dont know if my title is right and I'm sorry if it is wrong

    by the way here's the code

    private void InsertCitation_Click(object sender, RibbonControlEventArgs e)
            {
                // Insert a citation after the text just inserted to the bibliography
                // source added previously.
                Application wordApplication = Globals.ThisAddIn.Application;
                //wordApplication.Selection.EndKey(ref paramWdUnits,ref paramWdMovementType);
                wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeCitation, dropDown1.SelectedItem.Label/*ref paramBiblioSourceTag*/,
                    ref paramMissing);
    
                // Insert a page break after the citation added previously and then
                // add a bibliography to the document.
                wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType);
                wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak);
                
                //If find the Bibliography field in the document then update the field
                //otherwise insert a Bibliography field 
                bool isFoundFieldBibliography = false;
                foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
                {
                    if (field.Type == WdFieldType.wdFieldBibliography)
                    {
                        isFoundFieldBibliography = true;
                        //update BibliographyField
                        field.Update();
                    }
                }
                if (!isFoundFieldBibliography)
                {
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
                }
            
            }

    Thank you in advance

    More Power

    God Bless

    Thursday, January 23, 2014 2:36 AM

Answers

  • Hi,

    Based on my understanding, you want insert a citation after the existing citation, I suggest you create a bookmark to identify a location or a selection of existing citation. Using the wordApplication.ActiveDocument.Bookmarks.Add method to add a bookmark into end of citation, and then you could use the wordApplication.ActiveDocument.Bookmarks[].Range to get the location of bookmark,Here is a sample code for you reference:

              Application wordApplication = Globals.ThisAddIn.Application;
               if (!wordApplication.ActiveDocument.Bookmarks.Exists("Citation"))
                {
                    //wordApplication.Selection.EndKey(ref paramWdUnits,ref paramWdMovementType);
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                        ref paramWdFieldTypeCitation, ref paramBiblioSourceTag,
                        ref paramMissing);
                    wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType);
                    wordApplication.ActiveDocument.Bookmarks.Add("Citation", wordApplication.Selection);
                }
    
                else 
                {
                    wordApplication.ActiveDocument.Bookmarks["Citation"].Range.Fields.Add(wordApplication.ActiveDocument.Bookmarks["Citation"].Range,
        ref paramWdFieldTypeCitation, ref paramBiblioSourceTag,
        ref paramMissing);               
                }
                wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak);
                bool isFoundFieldBibliography = false;
                foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
                {
                    if (field.Type == WdFieldType.wdFieldBibliography)
                    {
                        isFoundFieldBibliography = true;
                        //update BibliographyField
                        field.Update();
                    }
                }
                if (!isFoundFieldBibliography)
                {
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
               }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by iGnjmz Wednesday, January 29, 2014 7:22 AM
    Friday, January 24, 2014 9:14 AM

All replies

  • Hi,

    Based on my understanding, you want insert a citation after the existing citation, I suggest you create a bookmark to identify a location or a selection of existing citation. Using the wordApplication.ActiveDocument.Bookmarks.Add method to add a bookmark into end of citation, and then you could use the wordApplication.ActiveDocument.Bookmarks[].Range to get the location of bookmark,Here is a sample code for you reference:

              Application wordApplication = Globals.ThisAddIn.Application;
               if (!wordApplication.ActiveDocument.Bookmarks.Exists("Citation"))
                {
                    //wordApplication.Selection.EndKey(ref paramWdUnits,ref paramWdMovementType);
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                        ref paramWdFieldTypeCitation, ref paramBiblioSourceTag,
                        ref paramMissing);
                    wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType);
                    wordApplication.ActiveDocument.Bookmarks.Add("Citation", wordApplication.Selection);
                }
    
                else 
                {
                    wordApplication.ActiveDocument.Bookmarks["Citation"].Range.Fields.Add(wordApplication.ActiveDocument.Bookmarks["Citation"].Range,
        ref paramWdFieldTypeCitation, ref paramBiblioSourceTag,
        ref paramMissing);               
                }
                wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak);
                bool isFoundFieldBibliography = false;
                foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
                {
                    if (field.Type == WdFieldType.wdFieldBibliography)
                    {
                        isFoundFieldBibliography = true;
                        //update BibliographyField
                        field.Update();
                    }
                }
                if (!isFoundFieldBibliography)
                {
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
               }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by iGnjmz Wednesday, January 29, 2014 7:22 AM
    Friday, January 24, 2014 9:14 AM
  • Hi Sir Marvin,

    Thank you for your reply,I have still problem Sir,the cursor(look like this " l "   the one that blinks) I want that after I insert a citation the cursor should be next to citation,look like this  " bla bla bla (citation1)l  "

    the one that look like small letter L sir is the cursor ..

    I want it like that so that if I have lots of sources save in the current list ,I will no longer scroll up to insert again a text,because in that code  I used Sir after I insert a citation the bibliography will be automatically put at the end of the document and  also the cursor so if I have lots of sources saved I will always scroll up to insert again a text.

    More Power to you sir Marvin thank you

    God Bless you


    • Edited by iGnjmz Monday, January 27, 2014 2:12 AM
    Monday, January 27, 2014 2:03 AM