#1
|
|||
|
|||
Toggle between pagecolumns / pagefit view
Hello!
I have this code that is toggle between pagecolumns / pagefit view. But it is not working properly. It only works the first time it runs. Any sugestions? Thanks. Code:
Sub View_Zoom_Alternate() If ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit Then With ActiveWindow.ActivePane.View.Zoom .PageColumns = 5 .PageRows = 2 End With Else ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit End If End Sub
__________________
Backup your original file before doing any modification. |
#2
|
||||
|
||||
wdPageFitBestFit has a value of 2 but when you set the line
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit word looks at the window size and sets the page zoom to best fit that window. Which means the return value of .PageFit is going to be a specific zoom number rather than 2. The more useful setting to hang your test on would be the .pagecolumns since bestfit is changing that to 1 and this would be consistent regardless of the window or paper size. Try... If ActiveWindow.ActivePane.View.Zoom.PageColumns = 1 Then
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thanks.
That's also not working, even this still not works: Code:
If ActiveWindow.ActivePane.View.Zoom.PageFit = 1 Or ActiveWindow.ActivePane.View.Zoom.PageFit = 2 Or ActiveWindow.ActivePane.View.Zoom.PageColumns = 1 Then..
__________________
Backup your original file before doing any modification. |
#4
|
||||
|
||||
So do some testing.
Start the macro by pressing F8 and hover over some of the values to see what values it is returning. eg. ActiveWindow.ActivePane.View.Zoom.PageColumns ActiveWindow.ActivePane.View.Zoom.PageFit Once you understand what values are being returned, you can choose the correct If test
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
I suspect the problem is not the IF statement, but this part has no effect after 1st run:
Quote:
__________________
Backup your original file before doing any modification. |
#6
|
|||
|
|||
Solved! The problem was that the page columns / rows are not reset when the pagefit/bestfit adjustment is set.
So It is necessary to set it back again to 1 when toggling to PageFitBestFIt Quote:
__________________
Backup your original file before doing any modification. |
#7
|
||||
|
||||
Just to clean it up a little now you've solved it
Code:
Sub Toggle_View_Zoom() With ActiveWindow.ActivePane.View.Zoom If .PageFit = wdPageFitBestFit Then .PageColumns = 5 .PageRows = 2 Else .PageColumns = 1 .PageRows = 1 .PageFit = wdPageFitBestFit End If End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
Thanks! A lot cleaner.
__________________
Backup your original file before doing any modification. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Toggle A4 and Custom size | gloub | Word VBA | 4 | 01-20-2019 05:00 PM |
Toggle Button | Squibble | Word VBA | 2 | 06-11-2014 05:36 PM |
Revision toggle without changing revision view? | New Daddy | Word VBA | 6 | 04-15-2014 05:59 PM |
Macro to toggle outline level | Jennifer Murphy | Word VBA | 3 | 01-22-2014 11:22 PM |
Toggle updates | dbugosh | Office | 2 | 12-16-2010 07:54 AM |