why is change event fired?

W

ward

Hello,
Another problem, this one concerning toolbars and
DocumentChange events:

I have a toolbar with a button to update all dynamic
content in the document (including headers and footers).
Clicking the button invokes the procedure UpdateAllFields
(see below for code).

I also have implemented a oApp_DocumentChange() event.
Everytime the event is fired I update some buttons on the
toolbar.

The strange thing is that the change event is fired when
my UpdateAllFields procedure has executed the firdt header
update code line
DocSec.HeaderswdHeaderFooterEvenPages).Range.Fields.Update

In fact, this doesn't bother me, but the problem is that i
get an error on the commandbar operations (invoked through
the change event) in the UpdateLanguage procedure (see
below). The error is 'Invalid procedure call or argument'.

Anybody who knows why the change event is fired, or why i
get an error on the commandbar.controls?

Ward


----------------------------
Public Sub UpdateAllFields()
'
'Update all the fields in the current document (without
'asking for confirmation)
'
Dim i As Integer
Dim DocSec As Section
Dim OrigRng As Range

Debug.Print "begin updateallfields"
If Application.Documents.Count = 0 Then Exit Sub

'Store current position/selection
Set OrigRng = Selection.Range

'Body text
Debug.Print "select everything"
Selection.WholeStory
Selection.Fields.Update

Debug.Print "update TOC"
For i = 1 To ActiveDocument.TablesOfContents.Count
ActiveDocument.TablesOfContents(i).Update
Next i

Debug.Print "update TOF"
For i = 1 To ActiveDocument.TablesOfFigures.Count
ActiveDocument.TablesOfFigures(i).Update

Next i

Debug.Print "update TOA"
For i = 1 To ActiveDocument.TablesOfAuthorities.Count
ActiveDocument.TablesOfAuthorities(i).Update
Next i

'Header & Footer
Debug.Print "update h&f"
For Each DocSec In ActiveDocument.Sections
Debug.Print " for each section"
DocSec.Headers
(wdHeaderFooterEvenPages).Range.Fields.Update
Debug.Print " first header updated"
' <-------------- change event invoked

DocSec.Headers
(wdHeaderFooterFirstPage).Range.Fields.Update
DocSec.Headers
(wdHeaderFooterPrimary).Range.Fields.Update
DocSec.Footers
(wdHeaderFooterEvenPages).Range.Fields.Update
DocSec.Footers
(wdHeaderFooterFirstPage).Range.Fields.Update
DocSec.Footers
(wdHeaderFooterPrimary).Range.Fields.Update
Debug.Print " last footer updated"
Next
Debug.Print "end update h&f"
'Restore original position/selection
OrigRng.Select
Debug.Print "end upadteallfields"
End Sub

---------------------------------------
Private Sub UpdateLanguage()
'
'Set mCurrentLanguage and correct state of the language
buttons
'
Dim Con As CommandBarControl

Debug.Print "update language"
If Application.Documents.Count = 0 Then Exit Sub

'Read language and set language settings
Debug.Print "read language settings"
If CustomPropertyExists(mLanguageProperty) Then
Select Case ActiveDocument.CustomDocumentProperties
(mLanguageProperty).Value
Case "NL"
mCurrentLanguage = LangNL
ActiveDocument.Styles
(wdStyleNormal).LanguageID = wdDutch
ReplaceVersionInFooters LangNL
Case "GB"
mCurrentLanguage = LangGB
ActiveDocument.Styles
(wdStyleNormal).LanguageID = wdEnglishUK
ReplaceVersionInFooters LangGB
Case Else
mCurrentLanguage = LangNone
End Select
Else
mCurrentLanguage = LangNone
End If

'Set buttons
Debug.Print "set buttons"
For Each Con In CommandBars(gToolbarName).Controls '<-
------ here I get an error !!!!!
If Con.Caption = "Language NL" Then
If mCurrentLanguage = LangNL Then
Con.State = msoButtonDown
Else
Con.State = msoButtonUp
End If
End If
If Con.Caption = "Language GB" Then
If mCurrentLanguage = LangGB Then
Con.State = msoButtonDown
Else
Con.State = msoButtonUp
End If
End If
Next

Set Con = Nothing

Debug.Print "end updatelanguage"

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