Macro for viewing size in zoom box

C

Clive Huggan

Dear all (and especially J.E.),

I'd like to create a button that will have the same result as inserting a
"110" (i.e., 110%) in the field in the zoom box. Can anyone help me with VBA
code on this, please? (Word 2001 on OS 9.2.2)

-- Clive Huggan
Canberra, Australia
============================================================
* Please post all comments or follow-on questions to the newsgroup for the
benefit of others who may be interested.
============================================================
 
D

Dayo Mitchell

Hi Clive,

Because I know *so much* about VBA I am a good person to answer this....
:) (severe sarcasm)

Recording the macro gets you this:

Sub Zoom110()
'
' Zoom110 Macro
' Macro recorded 12/13/03 by Dayo Nicole Mitchell
'
ActiveWindow.ActivePane.View.Zoom.Percentage = 110
End Sub

Which looks pretty clean. Assign a toolbar button (though you will likely
want to draw one in pixels since the provided icons are *so* unhelpful, I
think).

Unless I missed some hidden complexity in your question?

Dayo
 
J

J.E. McGimpsey

Dayo Mitchell said:
Recording the macro gets you this:

Sub Zoom110()
'
' Zoom110 Macro
' Macro recorded 12/13/03 by Dayo Nicole Mitchell
'
ActiveWindow.ActivePane.View.Zoom.Percentage = 110
End Sub

Which looks pretty clean. Assign a toolbar button (though you will likely
want to draw one in pixels since the provided icons are *so* unhelpful, I
think).

Unless I missed some hidden complexity in your question?

That's exactly how I would have gone about writing it...

Often a recorded macro needs some editing to make it more applicable
to a general situation. In this case, it doesn't.

But, liking to build all my toolbars from scratch on startup, I then
would store the macro in my my_startup.dot global macro, write
another one that restores the zoom to 100%, and insert this into my
toolbar routine:

With CommandBars("My Workbar").Controls
'lots of other controls
With .Add(Type:=msoControlButton)
.BeginGroup = True
.FaceId = 941
.OnAction = "Zoom110"
.TooltipText = "Zoom to 110%"
End With
With .Add(Type:=msoControlButton)
.BeginGroup = False
.FaceId = 2122
.OnAction = "Zoom100"
.TooltipText = "Zoom to 100%"
End With
End With

Or, what I'd usually do if I were feeling a bit fancy, is make a
toggle macro that alternates between 100% and 110% (and changes
button faces depending on the alternative), making use of the
button's .Parameter property:

With CommandBars("My Workbar").Controls
'lots of other controls
With .Add(msoControlButton, temporary:=True) 'Zoom
.FaceId = 941
.OnAction = "ZoomIt"
.Parameter = 110
.TooltipText = "Zoom to 110%"
.Tag = "ZoomToggle"
End With
'other controls
End With

Then instead of the Zoom110() and Zoom100() macros, I'd make one
macro that uses the button's .Parameter property to determine the
zoom, then switches the parameter, icon and tooltip properties for
the button:

Public Sub ZoomIt()
Dim nParm As Integer
nParm = CommandBars.ActionControl.Parameter
ActiveWindow.ActivePane.View.Zoom.Percentage = nParm
nParm = 210 - nParm 'Toggle between 100% & 110%
With CommandBars.FindControl(Tag:="ZoomToggle")
.Parameter = nParm
.FaceId = IIf(nParm = 100, 2122, 941)
.TooltipText = "Zoom to " & nParm & "%"
End With
End Sub

But neither are too different from what Dayo wrote.

Note: to toggle between other zoom values, change the

nParm = 210 - nParm

line. For instance, replacing 210 with 275 will toggle between 100%
and 175%.

BTW: The FaceID=941 is a pair of glasses - which seems appropriate
to me for increasing the zoom. The FaceID=2122 is "100%".
Unfortunately, there's no FaceID for 110% (but there are for
25%,50%, and 75%).
 
C

Clive Huggan

Thank you, John and Dayo!

Umm ... There wasn't any hidden complexity in the question, Dayo -- only
some faulty memory (human-type): I found a note I had written many months
ago reminding me about this one, and "recalled" that I had had difficulty
creating a macro for it. But now I have seen your responses, I conclude that
in reality it was only to remind me to try... <pause to reflect on passing
"senior's moment", albeit I'm only a pre-senior>

In any event, those elegant developments you suggest are *way* beyond my
capabilities to devise, John, and I'll certainly enjoy trying them.

Dayo, I've noticed your recent venturing into deeper waters with VBA. I'm
sure we're going to benefit further from it!

Cheers -- with many thanks to you both,

--Clive
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top