posts in 2011 8

August 4, 2011

MS Word Drawing Canvas Hack #2

(#3 was added on Oct 7. 2011.)

As I mentioned yesterday, we can “kaizen” the behavior of MS Word.

But it’s too much of a bother to call a macro everytime.
So let’s register these macro to the ribbon.

First, open “Option”. Then…

  1. Select “Ribbon Settings”
  2. Select “Macro”
  3. Select “Tool Tab” from “Ribbon Settings” and select “Drawing Tool > Format > Align”

Word Option

  1. Make new group
  2. Add macro
  3. And rename them

Make them as button

Then you can find buttons on the ribbon.
Buttons

Then you may get “Development” ribbon invisible.

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.
Sorry.

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)
    Else
        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.


Powered by WordPress, WP Theme designed by WSC Project.