How to perform a split (with a split bar) programmatically?

T

Tommy Svensson

Hi all,

Current scenario:

1. I have a document (document1) with English text
2. I have a translation macro assigned to button1
3. I press button1 which will translate document1 to Swedish in document2.

Now, I would like document1 and document2 to position themselves adjacently
like this:

+-----------+
| document1 |
+-----------+
| document2 |
+-----------+

or

+-----------+-----------+
| document1 | document2 |
+-----------+-----------+

with as little of decoration (toolbars, rules and stuff) around them as
possible.

Can this be done programmatically, i.e, is there support for doing this as
the last step in my translation macro?

==
Replies may very well be sent to me + the newsgroup!
==

/Tommy
 
H

Helmut Weber

Hi Tommy,
to hide all commandbars:
Sub HideToolbars()
Dim cb As CommandBar
For Each cb In Application.CommandBars
On Error Resume Next
If cb.Visible = True Then
cb.Visible = False
End If
Next
End Sub
to split windows vertically with doc(1) on the left side
(1024 x 768 pixel)
Windows(1).Height = 397
Windows(2).Height = 397
Windows(1).Width = 306
Windows(2).Width = 306
Windows(1).Top = 0
Windows(2).Top = 0
If Documents(1).Name = Windows(1).Caption Then
Windows(1).Left = 0
Windows(2).Left = 306
Else
Windows(1).Left = 306
Windows(2).Left = 0
End If
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
T

Tommy Svensson

Thx!

But if I want this behaviour to be bulletproof...? I.e, what can I do to
make all open windows none-maximized before adjusting the sizes of the
relevant windows? Because I get an error message when the windows are
maximized.

Also, how can I calculate the available space left for me to play around in?
I want things to work the same way as the "Split" menu choice in the window
menu but in a vertical manner. That function uses all available space.

/Tommy


Hi Tommy,
to hide all commandbars:
Sub HideToolbars()
Dim cb As CommandBar
For Each cb In Application.CommandBars
On Error Resume Next
If cb.Visible = True Then
cb.Visible = False
End If
Next
End Sub
to split windows vertically with doc(1) on the left side
(1024 x 768 pixel)
Windows(1).Height = 397
Windows(2).Height = 397
Windows(1).Width = 306
Windows(2).Width = 306
Windows(1).Top = 0
Windows(2).Top = 0
If Documents(1).Name = Windows(1).Caption Then
Windows(1).Left = 0
Windows(2).Left = 306
Else
Windows(1).Left = 306
Windows(2).Left = 0
End If
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
H

Helmut Weber

Hi Tommy,
"windows.arrange" as first line in "SplitV"
might help. But that isn't bulletproof either.
Of course, as you see from Jay's superb example,
it isn't that easy. You may even want more than just
arranging windows, like adjusting zoom factor and
horizontal scroll according to text width and horizontal
or vertical split. Even a kind of parallel scrolling,
both in vertical or horizontal split windows is possible.
I do editing in two languages and put the english text
always in the top or in the left window. Docs with
an even number in their name are in english, docs with
odd numbers are in german. Just an idea.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
L

Larry

These two macros work very well.

Sub VerticalSplit()

' Provided by Charles Eisler at public.word.general 3-17-00. To be run,
' there must be at least two Word documents open.

If Application.Windows.Count <> 2 Then
MsgBox "There must be exactly two document windows " & _
"open for macro to run.", , "Vertical Split"
Exit Sub
End If
'If Application.Windows.Count < 2 Or _
'Application.Windows.Count > 3 Then Exit Sub

' Restore the active document window and maximize the application window
ActiveWindow.WindowState = wdWindowStateNormal
Application.WindowState = wdWindowStateMaximize

' not necessary since I never have minimized windows
Dim numwins
numwins = Application.Windows.Count
For Each oWindow In Application.Windows
With oWindow
If oWindow.WindowState = wdWindowStateMinimize Then
numwins = numwins - 1
End If
End With
Next oWindow

If numwins > 0 Then
eachwide = Application.UsableWidth / numwins
Counter = 1
For Each oWindow In Application.Windows
With oWindow
If oWindow.WindowState = wdWindowStateMinimize Then
GoTo skip:
End If
.Top = 0
.Left = Counter
.Height = Application.UsableHeight
.Width = eachwide
End With
Counter = Counter + eachwide
skip:
Next oWindow

'set doc windows to wrap

For Each oWindow In Application.Windows
oWindow.View.WrapToWindow = True
Next oWindow

End If

End Sub

Sub VerticalSplitClose()

'set doc windows back to not wrap

For Each oWindow In Application.Windows
oWindow.View.WrapToWindow = False
Next oWindow

'Close one document window, maximize the other, and restore the app
window
ActiveWindow.Close
ActiveWindow.WindowState = wdWindowStateMaximize
Application.WindowState = wdWindowStateNormal
End Sub
 

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