Toggle view macro

B

Bob S

I am new to vba. I would love to write a simple conditional macro with two
states for viewing my document. If the current state of Zoom is 75%
(viewing the whole page) I would like the macro to switch to zoom of 150%.
And if the current zoom state is at any other %, I would like for it to
switch to 75%. It seems this would be very simple with an if statement.
But I do not know how to check or change the state of the zoom setting
within vba. Could someone help me with this? Thank you in advance. Bob
 
L

Lene Fredborg

The macro below should do what you want:

Sub ChangeZoom()

With ActiveDocument.ActiveWindow.View.Zoom
If .Percentage = 75 Then
.Percentage = 150
Else
.Percentage = 75
End If
End With

End Sub

Note that it is often helpful to record a macro in order to find out in
which direction you need to go. For example, recording a macro where you
change the zoom percentage to 75 will result in the following line:

ActiveWindow.ActivePane.View.Zoom.Percentage = 75

Se also:
http://word.mvps.org/FAQs/MacrosVBA/UsingRecorder.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
B

Bob S

Thank you very much Lene. The macro works like a champ, and your advice on
using the recorder was helpful too. In fact, I bookmarked the link you gave
for using the recorder to create macros and learn vba along the way. Thanks
again. Bob
 
B

Bob S

Good stuff. Thanks again.
Lene Fredborg said:
You are welcome. I am glad I could help.

Note that you will find many other helpful articles on the Word MVP Site.
For example, I think the article "Getting To Grips With VBA Basics In 15
Minutes" could be helpful for you now:
http://www.word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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