Welcome to MSDN Blogs Sign in | Join | Help

Keyboard Customizations and Macros in WordMail

In my first post on WordMail, I talked about how we fully integrated Word within Outlook for reading and writing emails. From a feature perspective, Word and WordMail are functionally the same. In other words, you have access to much of the same features in WordMail as in Word. However, from a technical perspective, Word and WordMail are two separate processes or entities. This is important to note because keyboard customizations and macros that work in Word will not automatically be available in WordMail. Today, I will show you how to add keyboard customizations and macros to WordMail for Office 2007.

Normal Email Template

As mentioned in this previous post, every document you create in Word is based off of a template. These templates store the look and feel of the document by specifying the appropriate styles. For the majority of cases, Word will use the Normal template whenever you create a new document. Similarly In the case of WordMail, every time you create an email you are creating a document based off of the NormalEmail template.

You might be asking yourself, why have separate normal templates for Word and WordMail, especially if the underlying application is just Word. Well, there are a couple of reasons:

  1. We wanted to differentiate the look of documents authored in Word 2007 vs. emails authored in Outlook 2007. In the case of Office 2007, Word and WordMail use different paragraph spacing values, which make for a different reading and authoring experience
  2. Because we separated Word and WordMail it was not possible for two separate applications to access one normal template at a time without running into issues. For example, trying to update the styles as defined in the normal template in both Word and WordMail may result in conflicts and synchronization errors. In other words, we would run into issues where one application had a lock on the template file while the other was trying to write back into the template

The reason I am bringing up templates is because keyboard customizations are stored within a document or template. In the case of email, keyboard customizations are stored in the NormalEmail template.

Keyboard Customizations in WordMail

Since we don't share keyboard customizations between Word and WordMail anymore, you will need to add your customizations separately for each application. To add keyboard customizations in WordMail you will need to do the following:

  1. Boot Word
  2. Click the Office Button
  3. Select Open
  4. In the Open dialog box, go to the following path %appdata%\Microsoft\Templates\
  5. Double click on the NormalEmail template
  6. Once the template is opened, click the Office Button again
  7. Click on Word Options
  8. Select the Customize tab, and click on Customize
  9. Add as many keyboard customizations as you would like
  10. Make sure to save changes in NormalEmail template

At this point, anytime you create a new email with WordMail you will have access to your keyboard customizations that you have just added.

Macros in WordMail

Similarly to keyboard customizations, macros don't automatically work in both "apps" if you create them in one "app." For example, let's say you tried to run the following macro to insert "hello world" into an email in Outlook 2007:

Word.Selection.TypeText "hello world"

The result you would see is a run time error of 424: Object required. With Outlook 2007 you will need to write your macros with Outlook in mind. Once you have access to the Outlook object you will then have access to the Word object. The above macro can be rewritten as follows to work with Outlook 2007:

ActiveInspector.WordEditor.Windows(1).Selection.TypeText "hello"

In other words, the Inspector.WordEditor property will give you full access to the Word object model.

With WordMail as the editor for other compose areas in Outlook, like tasks and appointments, you can write macros that will work exactly the same way in any of these Outlook items.

Accessing the Word OM in Outlook

By default, you will not see any intellisense for Word objects and properties if you try to access the Word object model in Outlook. Here is a way to remedy this limitation:

  1. Boot Outlook
  2. Hit Alt-F11 to invoke the VB editor
  3. Tools | References and add the following: (Microsoft Word 12.0 Object Library)

At this point in time you should be able to access the Word OM by declaring a document object and setting it to the WordEditor of a given compose note or read note:

In summary, there's Word and WordMail. They offer essentially the same feature set, but are two separate processes or entities.

Zeyad Rajabi

Published Monday, November 17, 2008 7:36 PM by wrdblog

Comments

# Keyboard Customizations and Macros in WordMail | Tmao Coders

# Content Controls in Word14

_Please_ tell me that you're going to have a way from within Word to link up content controls to a custom XML file.  Right now anyone who wants to take advantage of content controls and programmatically create documents needs to use the Content Control Toolkit, which (although it works great) is a joke.  We should be able to do that directly from within Word.  _Please_ tell me you're improving support for content controls in Word14.  _Pleeeeeeeeease?_

Thanks!

Tuesday, November 18, 2008 5:09 PM by Mesan

# re: Keyboard Customizations and Macros in WordMail

Did you actually try to use any of the keys that you reassigned using the method you described in "Keyboard Customizations in WordMail"? Although the steps you described will cause the customizations to be saved in NormalEmail.dotm, in my experience those customizations will not be recognized by the Outlook Wordmail editor. To eliminate any doubt you may have that I failed to follow the directions, let me say that I examined the file "customizations.xml" in the "Word" folder after unzipping NormalEmail.dotm and confirmed that the assignments had been added to the template.

In view of the foregoing, it probably does not make any difference, but you left out a couple of key steps in the description. Before editing NormalEmail.dotm, you must first close Outlook.

More significantly, in most cases what people will want to do is replicate in Outlook the key assignments they already have in Word. In that case, an essential step is to first remove the key assignment and then reassign it to NormalEmail.dotm. Otherwise Word will not recognize a change.

Finally, even if this roundabout customization method actually worked, it would not address the most important reason that your users desire to customize the keyboard--viz. to assign a keystroke to a macro. Since the keyboard customizations would have to be edited in Word, there would be no way to assign a shortcut to an Outlook macro. (The fact that you would have re-write your macros in Outlook is an additional nuisance.)

No offense, but your post exemplifies what is wrong with Microsoft Office development--the people who develop the programs don't actually use them in the way that business people do. Of course, you send e-mails to your friends and colleagues, but these are likely to use a telegraphic syntax. In contrast, when I communicate with clients, the message needs to be comparatively well-constructed, in order to retain their confidence. Accordingly, editing tools are important to help me swiftly and efficiently communicate in a manner that will not cause the recipient to shake his head in doubt.

The Word and Outlook teams have let people like me down. In Outlook 2003 and earlier, editing an e-mail was no different from editing in the same document Word--with all editing customizations. With Outlook 2007, we have been cut off at the knees.

Tuesday, November 18, 2008 8:40 PM by Michael H. Shacter

# re: Keyboard Customizations and Macros in WordMail

Michael,

Could you let me know what command(s) you tried to customize in WordMail? In addition to the command it would be good to know what shortcut key you tried to assign.

Yes, closing Outlook is necessary to get write access to NormalEmail.dotm. Thanks for clarifying.

In terms of replicating Word customizations in Outlook I was planning on writing a future post talking about a tool to accomplish this scenario. Currently, this task is quite manual as you describe.

The scenario you mention around accessing a macro via a keyboard customization is quite interesting. You should be able to assign a keyboard shortcut to a macro contained within NormalEmail. Is that not the case?

Could you explain a bit more on how you use editing tools to more “swiftly and efficiently communicate?” I really want to understand your scenario here to help figure out if something is missing in our current design.

Thanks,

Zeyad Rajabi

Tuesday, November 18, 2008 9:43 PM by BrianJones

# re: Keyboard Customizations and Macros in WordMail

You got my hopes up, but it seems that not all keyboard customizations make the translation into Outlook. I tried assigning ALT+S to do anything but send, but alas, it had no effect. (Thanks for adding the feature to disable send on CTRL+ENTER, but I still have sent out embarrasingly unfinished e-mails by hitting ALT+S by accident.)

Tuesday, November 18, 2008 11:39 PM by Francis

# re: Keyboard Customizations and Macros in WordMail

Hi Zeyad,

Many thanks for your cool response to my heated posting.

I tried three key reassignments: two that I use commonly and one other for experimentation. First, I tried assigning Ctrl+K to "ChangeCase" (the command that is natively bound to Shift+F3). Following this reassignment, Ctrl+K continued to function as "InsertHyperlink". Next, I tried assigning Ctrl+R to "EditReplace" (natively, Ctrl+H). Following this reassignment, Ctrl+R continued to function as "RightPara" (right paragraph justification). In each of these two cases, there was a key natively assigned to the function and a reassignment from one function to another. As a final experiment, I tried to associate an unused key to a function with no key assignment. I assigned "Strikethrough" to Alt+F12. This also produced no result. Incidentally, I am running Outlook 2007 (12.0.6316.5000) SP1 MSO (12.0.6320.5000) (part of Office Enterprise 2007) on Windows XP Professional SP3. What key assignments were you successfully able to change?

Incidentally, if I used "Alt+Ctrl+ Num +" (ToolsCustomizeKeyboardShortcut) to examine the key assignments, the reassigned keys appeared in the "Customize Keyboard" dialog. (I.e., (1) type "Alt+Ctrl+ Num +", (2) click "Format Text" on the ribbon, (3) click on the Strikethrough icon, (4) Alt+F12 appears in the "Current Keys" field, but has no effect when editing a message.) You mentioned "talking about a tool to accomplish this scenario". There already is a tool: "Alt+Ctrl+ Num +". Unfortunately, it does not save the changes to NormalEmail.dotm.

Outlook macros are not stored in NormalEmail.dotm. All Outlook macros--including those affecting the e-mail editor are stored in VbaProject.OTM. This is a change from earlier versions of Outlook, where Wordmail macros were stored in Word templates. Accordingly, I do not think an Outlook macro can be assigned to a keystroke in Word.

Here are a few of the macros I have assigned to keyboard shortcuts:

1. Delete to end of line (there is no native Word command for this fundamental function). As variants this function, I also have macros for "Delete to end of sentence" and "Delete line".

2. Paste as plain text (equivalent to "Paste Special" -> paste as unformatted Unicode text)

3. Toggle paragraph spacing (usually used to switch from automatic paragraph spacing to no spacing when typing a list--like this one)

4. Cut the entire word on which the cursor is located--regardless of insertion point--to the clipboard (equivalent to select word and then cut).

5. Toggle curly quotation marks

6. Insert space after insertion point. I frequently find the need to insert text when the cursor is at the beginning of another word. Starting to type causes the following word to appear misspelled. Moreover, formatting the word to be inserted (bold, italics, etc.) will cause the following word to be formatted to.

7. Correct misspelling and then return to insertion point. (I might be several words ahead when I discover a misspelled word. This brings me back to wherever the cursor was when I corrected an error. This is equivalent to Alt+F7, followed by Shift+F5, but only if I have not been cursoring around.)

You might be thinking that none of these macros (either individually or in the aggregate) sound like big timesavers--and you might be right. The point, however, is that these and other keyboard macros--along with key reassignments--are the way I am used to editing documents with Word and in Outlook. All the convenience I had from using the same editor for documents and e-mail messages is gone.

Mike

Wednesday, November 19, 2008 10:57 AM by Michael H. Shacter

# re: Keyboard Customizations and Macros in WordMail

Hi Mike,

Thanks for the detailed information.

You are right; we have a bug with WordMail with respect to not abiding to reassigned shortcut keys. I attempted to reassign ctrl-b to another command. Everything seems to work within NormalEmail, but does not function in WordMail. I will log this issue in our bug database.

We also have another issue where assigning to Alt-F9 does not work. Not too sure why at this point. However, assigning to Alt-9 does work. I will log a bug for this issue as well.

The tool I was talking about is a way to just copy over the xml contained within Normal to NormalEmail. Since both these templates are just xml files, this tool should be easy to write.

By the way, using Alt+Ctrl+Num + is a great and easy way to modify keyboard shortcuts for WordMail. Thanks for letting people know that trick as well.

I have a solution for assigning Outlook macros with shortcut keys (thanks to David Ngo). You need to create your macros within NormalEmail by taking into account Outlook. You then need to assign a shortcut key to that macro within NormalEmail. For example, the following macro, stored within NormalEmail, will insert text within WordMail:

Sub MSG_info()

   Dim oDoc As Word.Document

   Dim outlookApp As Outlook.Application

   Set outlookApp = GetObject(, "Outlook.Application")

   Set oDoc = outlookApp.ActiveInspector.WordEditor

   oDoc.Range.InsertBefore "hoho!!!"

End Sub

Hopefully that helps. Let me know if you run into any other issue.

Thanks,

Zeyad

Wednesday, November 19, 2008 3:11 PM by Zeyad Rajabi

# re: Keyboard Customizations and Macros in WordMail

Hi,

I'd like to suggest a topic for this blog:

What's the correct way to create/use a text data source for Word Mailings from an external application? With CSV format you often get problems as Word 2007 automatically chooses the Simple Chinese codepage instead of the Western Europe one. This gives chinese symbols for the German Umlauts like äöüÄÖÜß.

Also there's no conversion dialog shown when using MailMerge.Opendatasource to set the data source - regardless of its parameters or Options.DefaultTextEncoding you get always the wrong encoding when attaching certain csv files as data source.

The only way I've found to get the correct encoding for the text data source is to set the (for Word 2007) undocumented registry key HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options\DefaultCPG to DWORD 1252 (Western Europe)

But this suppresses the dialog also for user interactions like Office-Button/Open and manually attaching the data source.

In the Internet I've found many pages with questions asking for a solution to the problem.

And even only a few people found the DefaultCPG workaround.

So what's the correct way to programmatically create/open text data sources for Word Mailings with the correct encoding?

Stefan

Thursday, November 20, 2008 4:42 AM by Stefan

# re: Keyboard Customizations and Macros in WordMail

PS: Initially I'd hoped Word would also accept simple XML-Files (where you can give the encoding parameter within the file) as data source, Unfortunately it doesn't yet. Having to create OpenXML just to get a data source with the correct encoding would be no realistic option for many developers. :-/

Thursday, November 20, 2008 8:23 AM by Stefan

# re: Keyboard Customizations and Macros in WordMail

Hi Zeyad,

I hope your bug report won't be limited to the few keys mentioned in your posting. In my testing of the first 4 letters at the top of the keyboard (QWER), the majority of hot-key combinations did not work. The following did not work: Ctrl+Q, Ctrl+Shift+Q, Ctrl+Shift+W, Ctrl+E, Ctrl+Shift+E, Ctrl+R, Ctrl+Shift+R. Based on this small sample, it is fair to assume that the majority of key reassignments will not work.

Now that you have convinced me that it is possible to assign at least some keystrokes to the e-mail editor, I have a suggestion for a much easier method for making the assignments.

1. Close Outlook and then open NormalEMail.dotm in Word as suggested in your original posting.

2. In the "Customize Keyboard" dialog, click on "All Commands" and then assign "ToolsCustomizeKeyboard" to one of the keys that you know will accept key reassignments in Outlook, e.g. Alt+9.

3. Save the assignment to NormalEMail.dotm, as you described.

4. Re-open Outlook and type Ctrl+N to start a new message.

5. Click on the body of the message and type Alt+9. You can now assign any command to a key--assuming the Wordmail bug does not prevent the assignment.

Incidentally, I found that using Ctrl+/ as a prefix key offered many choices for the secondary key. For example, assigning "Ctrl+/, -" as a shortcut for Strikethrough.

With regard to the sample macro, since the macro is running in the Outlook process, it is not necessary to use the "GetObject" function call to get a reference to Outlook.Application. The following is sufficient:

 Set OutlookApp = Outlook.Application

Moreover, since the ActiveInspector method is a global procedure, and since one is unlikely to need an OutlookApp variable for any purpose other than to get a reference to the WordEditor object, the following is all that is required:

 Set oDoc = ActiveInspector.WordEditor

Note: If you wanted to edit your macros in Word using this abbreviated terminology, a reference should be set to the Microsoft Outlook 12.0 object library. Presumably, however, the favored manner of development would be to originate a macro in the Outlook VBA editor, where it would be stored in VbaProject.OTM. After the macro was debugged, it could be copied by cut/paste to NormalEMail.dotm in Word's VBA editor. It's a pity there is no way to do this directly in Outlook.

Here is another bug to add to report. Macro keystroke assignments are not visible in the Customize Keyboard dialog in Word or Outlook in sessions subsequent to the session in which the key was assigned. They keyboard assignments persist from session to session, but when you bring up the Customize Keyboard dialog, there is nothing in the "Current Keys" box (i.e. as if no key had been assigned to the macro). The assignments to native functions do appear in the "Current Keys" box.

Thanks for tackling this topic. I think it is fair to say that even you were surprised to learn the way key customizations and macros operate in Outlook.

Mike

Thursday, November 20, 2008 11:22 AM by Michael H. Shacter

# re: Keyboard Customizations and Macros in WordMail

Sorry, but my question is about email attachments, not about keyboards; however, I'm sure you can solve this one for me (or refer me to someone who can):

Recently I installed MS Office Home and Student 2007 and uninstalled MS Office XP Professional with Front Page. But now when others send me email attachments that are in .docx format, I cannot open them. Message says, "This action is only valid for products that are currently installed."  Can you help?

Gary Jacobsen

ggjacobsen@msn.com

Friday, December 19, 2008 4:38 PM by Gary Jacobsen

# re: Keyboard Customizations and Macros in WordMail

I've guessed how to do it earlier, but thanks for this detailed post anyway.

Thursday, January 15, 2009 1:37 AM by onscreen keyboard
New Comments to this post are disabled
 
Page view tracker