Microsoft’s Winword provides a facility to split the screen of the active document horizontally, but not vertically.
I searched for a way to do this on the Net, and was surprised when I couldn’t find one, so I wrote a macro myself.
It doesn’t split in exactly the same way as the horizontal split works, but it is effective.
The VBA macro takes the active window, makes it two, and then arranges them side by side.
I have annotated the code so it can be easily read and modified, which you are allowed to do (GNU).
The code splits the window into equal halves, but with some small adjustments could split it 1/3-2/3 or any other dimensions you require.
The code was only tested in Word 97 and Word 2007.
Sub SplitVertically() ' script by Anandajoti (GNU license) ' this macro takes the active window makes it two ' and then arranges them side by side ' if the active window is already duplicated ' it closes the duplicate instead Dim Win1 As Integer Dim Win2 As Integer Dim WinWidth As Integer Dim WinHeight As Integer ' the first part is a toggle function ' it looks to see if there are windows ' that have already been duplicated ' and if there are it closes the 2nd ' and maximises the first ' and then exits ' if you don't want/need this part delete up to "Next Win" Dim Win As Word.Window Dim DocString As String Dim FirstString Dim SecondString Dim StringLength As Long For Each Win In Application.Windows DocString = Win FirstString = Right(DocString, 1) If FirstString = "1" Then ' if there is a duplicate StringLength = Len(DocString) - 2 SecondString = Left(DocString, StringLength) ' close the copy Windows(SecondString & ":2").Close ' activate and maximise the doc that was found Windows(Win).Activate Windows(Win).WindowState = wdWindowStateMaximize ' jump to the end GoTo TheEnd End If ' otherwise check the next window Next Win ' if there are no duplicates ' make sure the window is maximised ' so we can get the necessary dimensions ' the view it is in is unimportant ActiveWindow.WindowState = wdWindowStateMaximize ' find the serial number of the window ' we are dealing with and set the variable Win1 = ActiveWindow.Index ' set the dimension variables WinHeight = ActiveWindow.Height - 20 WinWidth = ActiveWindow.Width ' make a new window from the first NewWindow ' find the serial number of the new window Win2 = ActiveWindow.Index ' arrange all windows (it won't work if the window is maximised) Windows.Arrange ' set the size of the two windows we found With Windows(Win1) .Left = 0 .Top = 0 .Height = WinHeight .Width = WinWidth / 2 End With With Windows(Win2) .Left = WinWidth / 2 .Top = 0 .Height = WinHeight .Width = WinWidth / 2 End With ' return to the first window Windows(Win1).Activate TheEnd: End Sub
or if you would prefer without annotation:
Sub SplitVertically() Dim Win1 As Integer Dim Win2 As Integer Dim WinWidth As Integer Dim WinHeight As Integer Dim Win As Word.Window Dim DocString As String Dim FirstString Dim SecondString Dim StringLength As Long For Each Win In Application.Windows DocString = Win FirstString = Right(DocString, 1) If FirstString = "1" Then StringLength = Len(DocString) - 2 SecondString = Left(DocString, StringLength) Windows(SecondString & ":2").Close ws(Win).Activate Windows(Win).WindowState = wdWindowStateMaximize GoTo TheEnd End If Next Win ActiveWindow.WindowState = wdWindowStateMaximize Win1 = ActiveWindow.Index WinHeight = ActiveWindow.Height - 20 WinWidth = ActiveWindow.Width NewWindow Win2 = ActiveWindow.Index Windows.Arrange With Windows(Win1) .Left = 0 .Top = 0 .Height = WinHeight .Width = WinWidth / 2 End With With Windows(Win2) .Left = WinWidth / 2 .Top = 0 .Height = WinHeight .Width = WinWidth / 2 End With Windows(Win1).Activate TheEnd: End Sub
If anyone can improve on the coding (and I wouldn’t be surprised) please leave a comment.
I hope this will be useful to others.
Anandajoti,
Greetings from London, and thank you for this wonderful little macro – it’s just what I was looking for! If it’s of any interest, your page was one of the first to be listed by DuckDuckGo for the search query: “word 2007” arrange windows vertically
Gratefully, Graham