Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2019, 07:04 PM
eduzs eduzs is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2010 32bit
Expert
Toggle between pagecolumns / pagefit view
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 05-05-2019, 10:21 PM
Guessed's Avatar
Guessed Guessed is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 05-06-2019, 03:19 AM
eduzs eduzs is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2010 32bit
Expert
Toggle between pagecolumns / pagefit view
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 05-06-2019, 04:32 AM
Guessed's Avatar
Guessed Guessed is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 05-06-2019, 05:00 AM
eduzs eduzs is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2010 32bit
Expert
Toggle between pagecolumns / pagefit view
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

I suspect the problem is not the IF statement, but this part has no effect after 1st run:
Quote:
With ActiveWindow.ActivePane.View.Zoom
.PageColumns = 5
.PageRows = 2
End With
__________________
Backup your original file before doing any modification.
Reply With Quote
  #6  
Old 05-06-2019, 06:09 PM
eduzs eduzs is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2010 32bit
Expert
Toggle between pagecolumns / pagefit view
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

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:
Sub Toggle_View_Zoom()

If ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit Then
With ActiveWindow.ActivePane.View.Zoom
.PageColumns = 5
.PageRows = 2
End With
Else
With ActiveWindow.ActivePane.View.Zoom
.PageColumns = 1
.PageRows = 1
End With
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
End If

End Sub
__________________
Backup your original file before doing any modification.
Reply With Quote
  #7  
Old 05-06-2019, 07:06 PM
Guessed's Avatar
Guessed Guessed is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #8  
Old 05-06-2019, 07:19 PM
eduzs eduzs is offline Toggle between pagecolumns / pagefit view Windows 10 Toggle between pagecolumns / pagefit view Office 2010 32bit
Expert
Toggle between pagecolumns / pagefit view
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

Thanks! A lot cleaner.
__________________
Backup your original file before doing any modification.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggle between pagecolumns / pagefit view Toggle A4 and Custom size gloub Word VBA 4 01-20-2019 05:00 PM
Toggle between pagecolumns / pagefit view Toggle Button Squibble Word VBA 2 06-11-2014 05:36 PM
Toggle between pagecolumns / pagefit view Revision toggle without changing revision view? New Daddy Word VBA 6 04-15-2014 05:59 PM
Toggle between pagecolumns / pagefit view 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft