M
murdoch
Hi
Has anyone a fix for this one please? It looks like a bug
to me.
I have 2 docs open in print layout view and run the code
below in the first doc. It runs OK. I then change to the
second doc and run the code again. After the "replace
all", Word has set the activewindow back to the first doc
and after entering the header, the activedocument has also
been reset to the first doc. The user is still in the
second doc but it is not properly active, ie no flashing
cursor and typing has no effect on either doc until the
user explicitly selects one. Also only the first doc
becomes dirty.
This is using Word 2003 (11.6113.5703) on WinXP Pro SP1 -
it does not happen in previous versions (2002, 2000, 97).
Many thanks for any help
' Test code:
Public Sub main()
Debug.Print
Debug.Print "---------------"
Debug.Print "start"
Debug.Print "Active Doc is " & ActiveDocument.Name
Debug.Print "Active Window is " & ActiveWindow.Caption
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey unit:=wdStory
With Selection.Find
.Text = "aaa" ' doesn't matter if this text
exists
.Replacement.Text = "bbb"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Debug.Print "---------------"
Debug.Print "after replace all"
' Active Doc still OK here ...
Debug.Print "Active Doc is " & ActiveDocument.Name
' ... but Active Window is now wrong
Debug.Print "Active Window is " & ActiveWindow.Caption
' next line errors if there is no such header (as
expected)
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryHeader
Debug.Print "---------------"
Debug.Print "after entering header"
' now Active Doc is wrong too
Debug.Print "Active Doc is " & ActiveDocument.Name
' and Active Window is still wrong
Debug.Print "Active Window is " & ActiveWindow.Caption
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
End Sub
Has anyone a fix for this one please? It looks like a bug
to me.
I have 2 docs open in print layout view and run the code
below in the first doc. It runs OK. I then change to the
second doc and run the code again. After the "replace
all", Word has set the activewindow back to the first doc
and after entering the header, the activedocument has also
been reset to the first doc. The user is still in the
second doc but it is not properly active, ie no flashing
cursor and typing has no effect on either doc until the
user explicitly selects one. Also only the first doc
becomes dirty.
This is using Word 2003 (11.6113.5703) on WinXP Pro SP1 -
it does not happen in previous versions (2002, 2000, 97).
Many thanks for any help
' Test code:
Public Sub main()
Debug.Print
Debug.Print "---------------"
Debug.Print "start"
Debug.Print "Active Doc is " & ActiveDocument.Name
Debug.Print "Active Window is " & ActiveWindow.Caption
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey unit:=wdStory
With Selection.Find
.Text = "aaa" ' doesn't matter if this text
exists
.Replacement.Text = "bbb"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Debug.Print "---------------"
Debug.Print "after replace all"
' Active Doc still OK here ...
Debug.Print "Active Doc is " & ActiveDocument.Name
' ... but Active Window is now wrong
Debug.Print "Active Window is " & ActiveWindow.Caption
' next line errors if there is no such header (as
expected)
ActiveWindow.ActivePane.View.SeekView =
wdSeekPrimaryHeader
Debug.Print "---------------"
Debug.Print "after entering header"
' now Active Doc is wrong too
Debug.Print "Active Doc is " & ActiveDocument.Name
' and Active Window is still wrong
Debug.Print "Active Window is " & ActiveWindow.Caption
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
End Sub