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
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 "Bob S" wrote: > 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 > > >
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 "Lene Fredborg" wrote in message news:269EAEEF-6F2C-4477-A9FC-770183574A47@microsoft.com... > 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 > > > "Bob S" wrote: > >> 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 >> >> >>
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 "Bob S" wrote: > 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 > "Lene Fredborg" wrote in message > news:269EAEEF-6F2C-4477-A9FC-770183574A47@microsoft.com... > > 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 > > > > > > "Bob S" wrote: > > > >> 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 > >> > >> > >> > > >
Good stuff. Thanks again. "Lene Fredborg" wrote in message news:BAAA8F38-0B77-4A2E-B98C-55C3197AD007@microsoft.com... > 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 > > > "Bob S" wrote: > >> 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 >> "Lene Fredborg" wrote in message >> news:269EAEEF-6F2C-4477-A9FC-770183574A47@microsoft.com... >> > 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 >> > >> > >> > "Bob S" wrote: >> > >> >> 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 >> >> >> >> >> >> >> >> >>