August 3, 2011

MS Word Drawing Canvas Hack

(#2 and #3 are available.)

Recently I’ve realized that there is a particular problem caused by the behavior of Microsoft Word 2010.
The behavior is that items on drawing canvas can not be aligned using align function.
c.f. Microsoft Answers

So I’ve written some tiny code to enable aligning them.

Here are some piece of screenshot to explain how to do.
However since I have only Japanese Environment so please imagine and guess what is told by them.

Drawing canvas & align function

Drawing canvas & align function

Lines in red font in a picture above means “Align functions are grayout and disabled for the items on drawing canvas”.

Then, the procedure below.
Please Poke your settings at your own risk. OK?

At first, to use macro and VBA, Make “Development” ribbon visible in the “Option” menu.
Word option

Then open “Visual Basic”.
Right click on “Normal” and insert “Module”.

Add 'Module'

Add 'Module'

This “Normal” is usually like a default settings included when a new document is created.
So once you add a macro code to it, you can use this function everytime you work with a new file.
And you don’t have to worry about things around security because this code will not be included in the document file itself.

Then copy the code below and paste to “Module1” in the module.

Private Sub AlignHorizontal(ARate As Single)
Dim Min, Max, i As Integer
    Min = 32768
    Max = -32768
    For Each AShape In Selection.ChildShapeRange
        If Min > AShape.Left Then
            Min = AShape.Left
        End If
        i = AShape.Left + AShape.Width / 20
        If Max < i Then
            Max = i
        End If
    Next AShape
    For Each AShape In Selection.ChildShapeRange
        AShape.Left = Min * (1 - ARate) + Max * ARate - AShape.Width / 20 * ARate
    Next AShape
End Sub

Private Sub AlignVertical(ARate As Single)
Dim Min, Max, i As Integer
    Min = 32768
    Max = -32768
    For Each AShape In Selection.ChildShapeRange
        If Min > AShape.Top Then
            Min = AShape.Top
        End If
        i = AShape.Top + AShape.Height / 20
        If Max < i Then
            Max = i
        End If
    Next AShape
    For Each AShape In Selection.ChildShapeRange
        AShape.Top = Min * (1 - ARate) + Max * ARate - AShape.Height / 20 * ARate
    Next AShape
End Sub

Private Sub AlignShape(AHorizontal As Boolean, ARate As Single)
    If Selection.ChildShapeRange.Count = 0 Then
        Exit Sub
    End If
    If AHorizontal Then
        AlignHorizontal (ARate)
        AlignVertical (ARate)
    End If
End Sub

Sub AlignHorizontalLeft()
    AlignShape True, 0
End Sub

Sub AlignHorizontalCenter()
    AlignShape True, 0.5
End Sub

Sub AlignHorizontalRight()
    AlignShape True, 1
End Sub

Sub AlignVerticalTop()
    AlignShape False, 0
End Sub

Sub AlignVerticalMiddle()
    AlignShape False, 0.5
End Sub

Sub AlignVerticalBottom()
    AlignShape False, 1
End Sub

Save the code, and that's all!

Select items on a drawing canvas, click "Macro" button on "Development" ribbon, select registered macro and execute.
Please guess which macro behaves how from the name of it.
It seems that it won't work with items OUTSIDE the drawing canvas.
Use the original align functions.

(2011.8.4: "Register macro to a button" Added.)

This code is free to use and you can change/rewrite it as you like.
But I'm happy if you provide some link to this page when you introduce this issue.

And I'm glad to know if there is some mistranslation of menu words or if there is some better way to solve this problem.
Let me know by comment below when you have something to tell me.
I'm not sure that I can reply all of the comments.
If such is the case, please disregard it.
Thank you.


  1. KineticFlow :

    Thanks very much, this worked!

  2. nezumiya :


    Thank you for your comment!

    I also wrote about “calling macro from buttons on ribbon”.

  3. Kees :

    Fantastic. Works like a dream. Thank you very much, and keep up the good work!

  4. Kees :

    Could you please also write a macro for “Distribute Horizontally” and “Distribute Vertically”? This is so very useful. Thank you.

  5. nezumiya :


    Thanks for your comment.
    “Distribute Vertically”…
    OK, I will try and let you know the result.

  6. Jen Thomas :

    Thanks for this — I’m writing a class on how to make flow charts in Word and was very upset to find this bug. Now I’m very grateful to you for the fix; you get a gold star for being a good e-citizen!

  7. nezumiya :


    I’m glad to know my info has been of help for you.
    And thank you for your comment!

  8. Steven :

    I’m amazed how well your solution fits in once shortcuts are added to the ribbon, I really wasn’t expecting such a seemless work around!

    Thanks again for posting!

  9. Richard :

    Thank you so much for providing a solution. Is it too much to ask to expand it to include the ‘distribute’ and the ‘align to canvas’ functions? That would be super!
    Thanks again for what you have done.

  10. nezumiya :

    Thank you for your hot comment 🙂

    Thank you for your comment and request, but on the following blogs you can also get a code for ‘distribute’,’align’ and put the functions on ribbon.
    I hope it will help you.

    blog #2
    blog #3

  11. Marcelo :

    Sweet! Really nice solution!

  12. Steve Jewess :

    Just a quick note to say thanks for this. My wife was trying to make a flowchart for her course-work in Word 2010, and the alignment problem was really annoying.

    Your solution is quick, elegant and effective. Many, many thanks.

  13. nezumiya :

    >Marcelo and Steve
    Thank you for leaving comments.
    Have fun with WORD 🙂

  14. wah :

    work like charm! thanks Arigato

  15. Paul Mundy :

    Nezumiya – you are a hero! Thanks!

  16. Fooje :

    This worked for me too. I am very grateful as I use shape connectors which can only be done in drawing canvas.

    Thank you so much for sharing this code.

  17. Steve :

    Nice work! So thankful for people like you. I have a new Hero!

  18. cory :

    master,how to distribute graph?

  19. cory :

    look forward to your work on graph distribution

  20. nezumiya :

    > wah, Paul, Fooje, Steve
    I’m glad that I could help you!

    > cory
    What kind of purpose do you have? and what kind of data do you have?
    It depends on what you want to do and the sort of data you have.

  21. slain :

    Hi there, yeah this piece of writing is in fact pleasant and
    I have learned lot of things from it on the topic of blogging.

Comment for this post

Powered by WordPress, WP Theme designed by WSC Project.