A family of Microsoft word processing software products for creating web, email, and print documents.
That isn't supposed to happen, because each pane maintains its own Selection object. When I switch panes, with or without a macro, the cursor always goes to its previous position in that pane.
Still, it is possible to force the cursor to the previous position in case that isn't working for you. Here's a modified macro that should do it.
Dim Pane1Range As Range
Dim Pane2Range As Range
Sub SwitchPanes()
With ActiveDocument.ActiveWindow
If .ActivePane.Index = 1 Then
Set Pane1Range = .Panes(1).Selection.Range
.Panes(2).Activate
If Not Pane2Range Is Nothing Then
Pane2Range.Select
End If
Else
Set Pane2Range = .Panes(2).Selection.Range
.Panes(1).Activate
If Not Pane1Range Is Nothing Then
Pane1Range.Select
End If
End If
End With
End Sub
Note that the two Dim statements must appear before the Sub statement (this is somewhat unusual, but it's necessary to make the variables keep their values from one run of the macro to the next).