none
How to make Microsoft Word add-in that insert citation and etc. RRS feed

  • Question

  • Hi,

    I want to make a Microsoft Word add-in that add bibliography source,choose bibliography style and insert citation in the active document, I looks like the Reference tab in the Microsoft Word

    I want to make this in c# if possible but I dont know how or where to start
    if you know it please tell me

    Thank you in advance
    More Power
    God Bless

    • Moved by TylorWang Tuesday, December 17, 2013 5:22 AM code issue
    Monday, December 16, 2013 12:16 PM

All replies

  • Hi,

    I successfully run an ms word add-in program but I have problem.

    here's my problem everytime I Insert a Citation ,all of the bibliography sources are inserted below and what I want is everytime I choose a Citation and press Insert Citation only the choosen Citation will be inserted in the document and the Bibliography that correspond to the choosen citation will be inserted at the end of the document .

    please check the Image(since I cant post an image here I just upload it in facebook)

    link for choosing a citation : https://www.facebook.com/photo.php?fbid=621398501229075&set=pcb.621398734562385&type=1&theater

    link for Inserting a Citation : https://www.facebook.com/photo.php?fbid=621398527895739&set=pcb.621398734562385&type=1&theater

    I only save two bibliography sources
    as you can see in the inserting citation image there are two bibliography and it should only 1 since I insert only 1 citation
    that's my problem
    I hope somebody will help me about this

    here's the code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    using Microsoft.Office.Interop.Word;
    
    namespace trialagain
    {
        public partial class Ribbon1
        {
            Application wordApplication = null;
            Document wordDocument=null;
    
            object paramMissing = Type.Missing;
            object paramWdUnits = WdUnits.wdStory;
            object paramWdMovementType = WdMovementType.wdMove;
    
            object paramWdFieldTypeCitation = WdFieldType.wdFieldCitation;
            object paramWdFieldTypeBiblio = WdFieldType.wdFieldBibliography;
    
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            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);            wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
            }
    
            private void RefreshBibliography_Click(object sender, RibbonControlEventArgs e)
            {
                Refresh_Bibliography();
            }
            private void Refresh_Bibliography()
            {
                this.dropDown1.Items.Clear();
                foreach (Source source in Globals.ThisAddIn.Application.ActiveDocument.Bibliography.Sources)
                {
                    RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
                    item.Label = source.Tag;
                    this.dropDown1.Items.Add(item);
                }
            }
        }
    }

    Thank you in advance
    More Power
    God Bless






    Thursday, December 12, 2013 7:29 AM
  • Hi,

    According to your description, you want  to insert the corresponding Bibliography when you insert a citation. As far as I know, the Bibliography in the Word is a special field. When we add this field in the document, it will get the source of bibliography right now.  If you insert a new Citation after inserting the Bibliography, the field will set to dirty. But Once you update the Bibliography, it will contain the corresponding source for the citation. We can hardly control the value via Object Model.

    You can press Alt & F9 to see the special field code. Figure below may help you to understand the Bibliography field:

    Best regards

    Fei


    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.

    Friday, December 13, 2013 9:58 AM
    Moderator
  • Hi sir Fei,

    so is that mean Sir that it is impossible to insert a citation and the corresponding bibliography be inserted at the end of the document?

    I just hope it is possible Sir 'cause this is our project and I don't have an idea how to do this :(

    please help me Sir Fei

    Friday, December 13, 2013 2:18 PM
  • Hi,

    I want to know how to achieve making a Reference tab like in Microsoft Word
    like adding Citation,Choosing a Bibliography style,adding some Biliography sources but I don't know where to start

    I hope someone can show me.

    If you know it please reply to this thread

    I'm begging.

    Sunday, December 15, 2013 10:08 AM
  • Hi iGnjmz,

    As far as I know, there is no such API we can acheve the goal. But there is a workaround to acheve it, when you add a new Citation you can remove all citation before. Then the bibilography you insert will correspond to the citation.

    Is it you what expected?

    Best regards

    Fei


    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.

    Monday, December 16, 2013 2:05 AM
    Moderator
  • Hi Sir Fei,

    I mean Sir is everytime I insert a citation into the active document the bibliography of the inserted citation will place below the document(please check the first link of image Sir) then if you add another citation still the bibliography of the inserted citation will be place below the document(please check the 2nd link of image image Sir)then the bibliography will adjust if the space of the document will be use(please check the third image Sir)

    1st link : https://www.facebook.com/photo.php?fbid=622977561071169&set=pcb.622977657737826&type=1&theater

    2nd link : https://www.facebook.com/photo.php?fbid=622977587737833&set=pcb.622977657737826&type=1&theater

    3rd link : https://www.facebook.com/photo.php?fbid=622977631071162&set=pcb.622977657737826&type=1&theater

    I hope you can help me with this Sir

    and I'm so thankful that someone like you replied to my thread
    More Power to you Sir Fei
    God Bless

    Monday, December 16, 2013 8:08 AM
  • Hello iGnjmz,

    Note, the current thread is for developers. That is why I would recommend asking such questions in the Word IT Pro forum.

    Go to FILES -> Options -> Customize Ribbon (see the screenshot below):

    Monday, December 16, 2013 9:10 AM
  • Hi,

    I want to know how to achieve making a Reference tab like in Microsoft Word in the form of add-in,
    like adding Citation,Choosing a Bibliography style,adding some Biliography sources but I don't know where to start

    I hope someone can show me.

    If you know it please reply to this thread

    I'm begging.

    • Merged by TylorWang Tuesday, December 17, 2013 3:02 AM duplicate
    Monday, December 16, 2013 11:46 AM
  • Hi Sir Eugene,

    Okay Sir and by the way I don't see Customize Ribbon in my MS Word 2007 sir Only the Customize Quick Access Toolbar


    Thank you for your reply Sir.
    Monday, December 16, 2013 11:48 AM
  • Hi,

    I want to make a Microsoft Word add-in that add bibliography source,choose bibliography style and insert citation in the active document, I looks like the Reference tab in the Microsoft Word

    I want to make this in c# if possible but I dont know how or where to start
    if you know it please tell me

    Thank you in advance
    More Power
    God Bless

    • Merged by Marvin_Guo Tuesday, December 17, 2013 12:43 PM the same
    Monday, December 16, 2013 12:13 PM
  • The screenshot was made on my machine with Word 2013 installed.

    Please take a look at the Customize The MS Word 2010 Ribbon By Adding Your Own Tab With Commands You Use Most Often article (describing Word 2010).

    Monday, December 16, 2013 12:20 PM
  • Hi

    This is the forum to discuss questions and feedback for Microsoft Outlook, better to post your question to the forum for Exchange

    http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards

    Tylor Wang
    TechNet Community Support

    Tuesday, December 17, 2013 4:34 AM
  • Hi Sir Eugene,

    but I want to make this in a form of MS Word add-in using c#
    is this possible Sir?
    if you know some article that can help achieve this can you tell me?

    Thank you in advance Sir Eugene.
    Tuesday, December 17, 2013 7:23 AM
  • Hi Ignjmz,

    According to your last reply, you want to update the Bibliography field if the Bibliography field existed in the document rather than insert the Bibliography field again. I wrote a small sample for your reference:

    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);
                }
            
            }
    

    Best regards

    Fei


    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.

    Tuesday, December 17, 2013 12:41 PM
    Moderator
  • Hello,

    Please take a look at the Customizing the 2007 Office Fluent Ribbon for Developers  article. It describes all the required steps to get the job done.

    Tuesday, December 17, 2013 9:34 PM
  • Hi Sir Fei,

    I used the code you made Sir and still when I insert a citation all of the bibliography are inserted below not the bibliography of the inserted citation, by the way Sir Fei I found some video  exactly the same to what I want to happen in this add-in, I was searching a video that can help me to my problem when I suddenly found this one 

    link : http://www.youtube.com/watch?v=HSNK1YUA7hU

    Thank you so much Sir Fei

    Wednesday, December 18, 2013 5:41 AM
  • Hi Sir Eugene,

    Do you know some article or forum that somebody post about on how to save bibliography source programmatically using c# in the form of add-in?

    Thank you in advance Sir
    More Power
    God Bless

    Wednesday, December 18, 2013 10:44 AM
  • It looks like your question is not related to the initial one. If so, I would recommend marking this thread as answered and asking a new question in a separate thread. It will allow others to find the answer easily.

    Wednesday, December 18, 2013 11:09 AM
  • Hi Sir Eugene,

    I'm still asking Sir 'cause I'm still looking for a solution for this one sir like saving bibliography sources and I'm
    sorry for the late reply because I'm still searching in google how to solve my problem
    I really want to make this in c#

    can you help me sir?

    • Edited by iGnjmz Wednesday, December 18, 2013 11:19 AM
    Wednesday, December 18, 2013 11:19 AM
  • Hi iGnjmz,

    Thanks for sharing the details with us.

    The sample above will always update the Bibliography to latest. To achieve the goal, we need to remove all the source in the active document before adding a new source to document. But this is impossible, the reason is that we can’t remove the source which has been insert in the document via Source.Delete. It will throw an exception.

    If you think this is a feature that Word should provide, I suggest you submitting the feedback via submit feedback.

    Best regards

    Fei


    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.

    Monday, December 23, 2013 11:30 AM
    Moderator
  • Hi Sir Fei,

    Sorry for the late reply,I was in a Christmas vacation Sir Fei
    So you mean Sir it is impossible to do this?  

    Oh my :(

    I was wondering how did the Endnote make it happen like this in the video 
     http://www.youtube.com/watch?v=HSNK1YUA7hU

    anyway thanks Sir,I will try my luck again,I hope someone knows how to do this :(

    More Power Sir and Thank you

    Saturday, December 28, 2013 10:54 AM