Big Bug in Word?

T

TCook

Hey All,

Just wondering if anyone else has experienced the same bug that I have in MS
Word:

Create a single class module called WordEventClass as follows:




Option Explicit

Private WithEvents m_appWord As Word.Application

Private Sub Class_Initialize()
Set m_appWord = Word.Application
End Sub

Private Sub Class_Terminate()
Set m_appWord = Nothing
End Sub

Private Sub m_appWord_WindowSelectionChange(ByVal Sel As Selection)
MsgBox "SelectionChange"
End Sub





Now create a regular module as follows:




Option Explicit

Private MyClass As WordEventClass

Sub starter()
Dim pPara As Word.Paragraph

Set MyClass = New WordEventClass

For Each pPara In Selection.Paragraphs
Debug.Print pPara.LeftIndent
Debug.Print pPara.RightIndent
Debug.Print
pPara.Range.Information(wdHorizontalPositionRelativeToPage)
Debug.Print pPara.Range.Information(wdActiveEndPageNumber)
Next pPara
End Sub



Notice how the 'WindowSelectionChange' event fires like crazy???

It appears that reading LeftIndent, RightIndent and Information fires the
'WindowSelectionChange' event... and how is this going to negatively affect
performance???

Does anyone have any experience with this?

It's easy enough to avoid within one's own solutions via setting some flag
to skip the 'WindowSelectionChange' code but when there may be other 3rd
party tools involved, it could get ugly in a hurry.

Thoughts?
 
T

Tony Jollans

I don't see this behaviour - tried it in Word 2000 on Win 2000 and also Word
2003 in Vista, and in both environments it all worked properly.
 
J

Jean-Guy Marcil

TCook was telling us:
TCook nous racontait que :
Hey All,

Just wondering if anyone else has experienced the same bug that I
have in MS Word:

Create a single class module called WordEventClass as follows:




Option Explicit

Private WithEvents m_appWord As Word.Application

Private Sub Class_Initialize()
Set m_appWord = Word.Application
End Sub

Private Sub Class_Terminate()
Set m_appWord = Nothing
End Sub

Private Sub m_appWord_WindowSelectionChange(ByVal Sel As Selection)
MsgBox "SelectionChange"
End Sub





Now create a regular module as follows:




Option Explicit

Private MyClass As WordEventClass

Sub starter()
Dim pPara As Word.Paragraph

Set MyClass = New WordEventClass

For Each pPara In Selection.Paragraphs
Debug.Print pPara.LeftIndent
Debug.Print pPara.RightIndent
Debug.Print
pPara.Range.Information(wdHorizontalPositionRelativeToPage)
Debug.Print pPara.Range.Information(wdActiveEndPageNumber)
Next pPara
End Sub



Notice how the 'WindowSelectionChange' event fires like crazy???
No.

Tried your code as is on Word 2003 (latest patches) and on Windows XP-SP2.

The MsgBox never popped up during the execution of the "starter" sub,
regardless of the number of paragraph selected.

You may have some other add-in that is interfering...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jezebel

Doesn't happen for me either. There's nothing in that code that fires the
SelectionChangeEvent.
 
T

TCook

Hey All,

Is it turns out, there was something else interfering but Word was also
partly to blame.

When I went into Tools -> AddIns, I noticed an old template listed there.
After removing it, no problems.

However, here's what's extremely strange: the template was neither loaded
nor currently existed on my system as it had been deleted some time ago.

Very, very odd.

In any event, thanks for the assistance as it was helpful.

Best,

TC
 

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