View Single Post
 
Old 10-15-2013, 02:16 PM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
Thank you for the update. Again, I learn something new!
This is the code I ended up using in a MacroButton Controller class:

Code:
Option Explicit
Private WithEvents wordApp As Word.Application
Private currentButtonClick As Integer
Private TemplateDoc As Document
'*************************************************************************
' Initialize class - Create objects and set values to defaults.
'*************************************************************************
Private Sub Class_Initialize()
    currentButtonClick = Options.ButtonFieldClicks
    Set wordApp = Application
    Set TemplateDoc = ActiveDocument
    Call setButtonClick
End Sub
'*************************************************************************
' Terminate class - Cleanup code.
'*************************************************************************
Private Sub Class_Terminate()
    Call restoreButtonClick
    Set wordApp = Nothing
    Set TemplateDoc = Nothing
End Sub
'*************************************************************************
' Application EVENT HANDLERS
'*************************************************************************
Private Sub wordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    If CheckDoc(Doc) Then
        Call restoreButtonClick
    End If
End Sub
Private Sub wordApp_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    If CheckDoc(Doc) Then
        Call setButtonClick
    End If
End Sub
Private Sub wordApp_WindowDeactivate(ByVal Doc As Document, ByVal Wn As Window)
    If CheckDoc(Doc) Then
        Call restoreButtonClick
    End If
End Sub
''*************************************************************************
'' UTILITY functions
''*************************************************************************
Private Function CheckDoc(Doc As Document) As Boolean
    If Not (TemplateDoc Is Nothing) Then
        If Not (Doc Is Nothing) Then
            CheckDoc = (Doc = TemplateDoc)
        End If
    End If
End Function
Private Function setButtonClick()
    Options.ButtonFieldClicks = 1
End Function
Private Function restoreButtonClick()
    Options.ButtonFieldClicks = currentButtonClick
End Function
I appreciate the help, I wouldn't have known that there was a setting for this without your responses. Thanks again
Reply With Quote