Outlook Subject Line using MS Word SendMailAttach

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Outlook Subject Line using MS Word SendMailAttach

Post by JimmyC »

I am using Word 2010 & Outlook 2010. I have the following macro:

Sub JCC_Send_Document()
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub


It works, but the Outlook subject line is the name of the attached document---which I assume is the "default" behavior. Is there anyway to specify the Outlook subject line to be "New Client/Matter Open Request" . I would want this Outlook subject line in all instances when the macro is executed and not have the Outlook e-mail subject line default to the file name of the attached word document. Is this possible?

Finally, is it possible to also populate the "send to" field? All e-mails generated by the macro will be sent to the same e-mail account.

Thanks
JimC

User avatar
HansV
Administrator
Posts: 78930
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook Subject Line using MS Word SendMailAttach

Post by HansV »

You'd need to automate Outlook. You can use the following as starting point:

Code: Select all

Sub JCC_Send_Document()
    Dim objOL As Object
    Dim objMsg As Object
    If Not ActiveDocument.Saved Then
        ActiveDocument.Save
    End If
    Set objOL = CreateObject("Outlook.Application")
    Set objMsg = objOL.CreateItem(0)
    With objMsg
        .Subject = "My Subject"
        .To = "someone@somewhere.com"
        .Attachments.Add ActiveDocument.FullName
        .Body = "Please see the attached document" & vbCrLf & _
            "Yours Sincerely," & vbCrLf & _
            "JimmyC"
        .Display
    End With
End Sub
Best wishes,
Hans

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: Outlook Subject Line using MS Word SendMailAttach

Post by JimmyC »

Hans--thank you!

I thought that I knew how to do the next step. I was wrong.

I guess Word 2010 is different than Excel 2010. I would like to have a button in the top left corner of the document that when the user clicks it, the macro you provided me fires. I have created the button in Word and located it where I want it, but unlike Excel when I right click the button that is not an option to "assign macro". I have found code on the internet that creates a command button on a document, but it creates the command button on a new blank document and not my document plus it also appears that I can't move the command button to the desired location on the page.

Can you send me in the right direction to figure this out? Wow, I feel like a fool.

Thanks again.
JimC

User avatar
Jay Freedman
Microsoft MVP
Posts: 1320
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Outlook Subject Line using MS Word SendMailAttach

Post by Jay Freedman »

One (not very good) option is to use an ActiveX command button (in the menu of the Legacy Tools button on the Developer tab). Use its Properties dialog to set the button's caption. Right-click the button and click View Code, which automatically creates a Sub in the ThisDocument module. Put Hans's code into that Sub (the name of the Sub is specific to that command button). The reason I say it's not very good is that ActiveX objects were intended for use in web pages and were kind of shoehorned into Office; they sometimes cause problems.

An easier and more stable method is to insert a MacroButton field in the document, with your macro's name following the MacroButton keyword, and with the display text after that. You can format the field's display text to look like a button by adding a border and shading to it. A minor gotcha is that it normally takes a double-click on the field to run the macro; to fix that, run the code

Options.ButtonFieldClicks = 1

in an AutoOpen macro.

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: Outlook Subject Line using MS Word SendMailAttach

Post by JimmyC »

Jay---thank you. I will explore this route later tonight after dinner or when I get back to office for Friday. Jim

User avatar
HansV
Administrator
Posts: 78930
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook Subject Line using MS Word SendMailAttach

Post by HansV »

Jimmy: I had not seen that you edited your previous reply to add questions - the timestamp of a reply doesn't change if you edit it. Therefore, it is better to start a new reply if you have additional questions.

Jay has given you some excellent suggestions. You can also assign a custom keyboard shortcut and/or a custom Quick Access Toolbar button to the macro.
Best wishes,
Hans

User avatar
Charles Kenyon
5StarLounger
Posts: 641
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Outlook Subject Line using MS Word SendMailAttach

Post by Charles Kenyon »

You can also add a QAT modification to your document template that contains the macro. The one problem is trying to make sure your user notices it. If it is you, though, it is simple.

http://addbalance.com/word/QATmodification.htm

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: Outlook Subject Line using MS Word SendMailAttach

Post by JimmyC »

Hans--thank you for your posting advice.

I should have tried the button with the code first prior to my "thank you" reply as it was not until after the post that I realized that Excel and Word function totally different in regard to macro buttons. When my google solutions failed regarding the button that is when I realized I needed more help. Rather than create another post, I just appended the "thank you" one. I will be more diligent moving forward.

I have an "emergency" task this morning but hope to try out the advice this afternoon. What I am working on will be used by 80 employees---so it has to be "fool proof" and "easy".

As always, I am greatly appreciative for those that freely give of themselves to help others in this lounge--you are truly a blessing to many like me!
Jim

JimmyC
3StarLounger
Posts: 382
Joined: 08 Feb 2010, 16:08

Re: Outlook Subject Line using MS Word SendMailAttach

Post by JimmyC »

Jay,
An easier and more stable method is to insert a MacroButton field in the document, with your macro's name following the MacroButton keyword, and with the display text after that. You can format the field's display text to look like a button by adding a border and shading to it. A minor gotcha is that it normally takes a double-click on the field to run the macro; to fix that, run the code.
Is there anyway to drag the MacroButton to the desired location? I need the button in the upper left hand corner of the document. I just can't seem to "move" the MacroButton once its inserted in the document. Is it possible to actually insert the MacroButton in the top left portion of the header? I haven't found anything on the internet about either dragging the macrobutton to a desired location or placing it in the header, so neither option must be possible--but I thought that I would confirm.

I never would have thought that placing a macro button in a Word document would be so difficult when its so easy in Excel.

Thanks
Jim

User avatar
HansV
Administrator
Posts: 78930
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook Subject Line using MS Word SendMailAttach

Post by HansV »

A macro button is part of the text; you can cut & paste it to any part of the document text.

You could position a macro button in the page header, but I don't think that's a good idea - the user would have to activate the header first, then the macro button.

A keyboard shortcut or Quick Access Toolbar button is probably a better option.
Best wishes,
Hans