none
Having an attachment feature for mail merge for Word 2007 RRS feed

  • Question

  • Trying have the mail merge feature for the Word as it pops up a window to choose the Subject line and To field. I want to add an option to attach a file here how is that possible? I have developed my own window that looks similar to the window but unable to get any kind of information like the basic ones like the To field to be populated..this is my code

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using System.Windows.Forms;
    
    
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new Ribbon1();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace mailmerge_addin
    {
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
    
            public Ribbon1()
            {
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("mailmerge_addin.Ribbon1.xml");
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            public void dlgMergeToEmail(Office.IRibbonControl control, ref bool CancelDefault)
            {
    
                Mailmerge actual_form = new Mailmerge();
                actual_form.Show();
               // actual_form.IsMdiContainer = true;
                
    
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
        }
    }
    

    and this is what i get for my add-in

    But where as the original/ default one looks like this for the same document nothing is in the To: field even though  i have choosen the recipents


    D.Boy

    Tuesday, March 27, 2012 3:41 PM

Answers

All replies

  • if 'Mailmerge' is a form that you created then it is your own responsibility to fill data there to mimic existing form - word will not take over and do it for your - if you redirect existing button to invoke your own code you have to do _everything_ yourself.
    Wednesday, March 28, 2012 8:35 AM
  • OK no issues there but one thing i am not sure is how to get the list of contacts that the Word has acquired previously, becuase if we go thru the steps of mailmerge then there is the option to choose existing contact list and the contacts are populated and this will be reflected in the default window but i want this to be reflected in my 'Mailmerge' window as well if it is possible..tks

    D.Boy

    Wednesday, March 28, 2012 9:04 AM
  • Look at Document.MailMerge, there is everything that word exposes regarding mail merge.
    Wednesday, March 28, 2012 9:44 AM
  • Not sure how to word the question.

    So i will try to be clear what i want here, i basically would like to know when the 'Finish&Merge' options


    the Send E-mail Messages is pressed presenting the user with this dialogbox


    So basically here when the user press OK i want to caputre that event, how can i do that? Cause i want to show a message box of confirmation and do some other activity after the ok is pressed.

    Sorry that there is no code to present.

    word 2007

    vs2010 (all updates and latest VSTO)


    D.Boy



    Sunday, April 1, 2012 2:40 AM
  • Hi D.Boy,

    Thanks for posting in the MSDN Forum.

    It's based on my experience that you are able to access MailMergeDataSource to address your goal. MailMergeDataSource reference: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.mailmergedatasource_members.aspx.

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 2, 2012 5:29 AM
    Moderator
  • Hi D.Boy,

    Thanks for posting in the MSDN Forum.

    I'm not able to see the images that you want to show. Would you please modfiy your post to show it? And it will make sense if you are able to tell me your Word version and Visual Studio version.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 2, 2012 7:26 AM
    Moderator
  • Updated excuse the previous post with out pics, didn't realize that, btw copy paste of img is not working when posting the img in the question

    D.Boy


    Monday, April 2, 2012 3:32 PM
  • Hi D.Boy,

    Sorry, I still can't see first image. And I suppose you have post a duplicated post, the original post is : http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/675d112b-b09e-4db6-a1a8-6b55c2732340. Is it right?

    Have a good day,

    Tom 


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 3, 2012 9:00 AM
    Moderator
  • no tom sorry for the confusion this is a different question

    Not sure how to word the question.

    So i will try to be clear what i want here, i basically would like to know when the 'Finish&Merge' options


    the Send E-mail Messages is pressed presenting the user with this dialogbox

    NOT SURE Y UR NOT ABLE TO VIEW THE PICTURE BUT ANYHOW HERE IS THE WEBLINK FOR THE IMG .

    http://www.farfromfearless.com/wp-content/uploads/HowToUseMailMergeInMicrosoftWord_111CC/send.jpg

    So basically here when the user press OK i want to caputre that event, how can i do that? Cause i want to show a message box of confirmation and do some other activity after the ok is pressed.

    Sorry that there is no code to present.

    word 2007

    vs2010 (all updates and latest VSTO)


    D.Boy

    Tuesday, April 3, 2012 3:22 PM
  • Hi D.Boy,

    I'm sorry, I don't know whether it correct on your side. However this is the screen shooting on my side. I'm still see nothing about your first image.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 5, 2012 7:44 AM
    Moderator
  • Hi Tom ,

    Thats Ok it is another mystery we wont be able to resolve i guess!

    But i also included the weblink for the img right? if you missed it, it is over here

    http://www.farfromfearless.com/wp-content/uploads/HowToUseMailMergeInMicrosoftWord_111CC/send.jpg

    So do take note. Tks for your constant support


    D.Boy

    Thursday, April 5, 2012 9:56 AM
  • Hi jackandjill2012,

    I guess you want to subscribe the event of MailMergeAfterMerge event. Please let me know whether it can solve your issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 10, 2012 8:26 AM
    Moderator
  • JACKPOT!

    But the exactly what i want is when the user presses OK then an event to fireup so before even the first record is being merged i want to get in to that. not after the mailmerge has completed. Tks Tom


    D.Boy

    Tuesday, April 10, 2012 9:35 AM
  • Hi D.Boy,

    So you want MailMergeBeforeMerge event. Is it right?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 11, 2012 6:08 AM
    Moderator