VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ThisWorkbook"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
' Copyright (C) 2007 Stephane Germain <stephane.germain@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or (at
' your option) any later version.
'
' This program is distributed in the hope that it will be useful, but
' WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
' General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

Option Explicit
Option Base 0

Private Sub Workbook_AddinInstall()
    On Error Resume Next
    Dim lngPos, i As Long
    Dim objToolsMenu As CommandBar
    Dim objToolsSubMenu As CommandBarControl
    Dim objToolsMenuItem As CommandBarControl
    Dim objExcelAbout As CommandBarControl
    
    ReadSetting
    
    'Get reference to Tools menu
    Set objToolsMenu = Application.CommandBars("Tools")
    lngPos = objToolsMenu.Controls.Count
    
    For i = lngPos To 1 Step -1
        If objToolsMenu.Controls(i).Caption = ProgName Then
            objToolsMenu.Controls(i).Delete
        End If
    Next i
    
    lngPos = objToolsMenu.Controls.Count
    ' Add menu item
    Set objToolsSubMenu = objToolsMenu.Controls.Add(msoControlPopup, 1, , lngPos, False)
    objToolsSubMenu.Caption = ProgName
    
    Set objToolsMenuItem = objToolsSubMenu.Controls.Add(msoControlButton, 1, , _
                          1, False)
    objToolsMenuItem.Caption = GText("menuStart")
    objToolsMenuItem.OnAction = "StartWirt"
    
    Set objToolsMenuItem = objToolsSubMenu.Controls.Add(msoControlButton, 1, , _
                          2, False)
    objToolsMenuItem.Caption = GText("menuHelp")
    objToolsMenuItem.OnAction = "WirtHelp"
    
    Set objToolsMenuItem = objToolsSubMenu.Controls.Add(msoControlButton, 1, , _
                          3, False)
    objToolsMenuItem.Caption = GText("menuSettings")
    objToolsMenuItem.OnAction = "WirtSettings"
    
    Set objToolsMenuItem = objToolsSubMenu.Controls.Add(msoControlButton, 1, , _
                          4, False)
    objToolsMenuItem.Caption = GText("menuAbout")
    objToolsMenuItem.OnAction = "AboutWirt"
    
    'MsgBox GText("msgAddInInstalled", ProgName), vbApplicationModal, ProgName
End Sub

Private Sub Workbook_AddinUninstall()
    On Error Resume Next
    Dim lngPos, i As Long
    Dim objToolsMenu As CommandBar
    Dim objToolsMenuItem As CommandBarControl
    Dim objExcelAbout As CommandBarControl
    
    'Get reference to Tools menu
    Set objToolsMenu = Application.CommandBars("Tools")
    lngPos = objToolsMenu.Controls.Count
    
    For i = lngPos To 1 Step -1
        If objToolsMenu.Controls(i).Caption = ProgName _
            Or objToolsMenu.Controls(i).Caption = "&eirt" _
            Or objToolsMenu.Controls(i).Caption = "wirt" Then
            objToolsMenu.Controls(i).Delete
        End If
    Next i
End Sub

Private Sub Workbook_Open()
    On Error Resume Next
    WirtSerial = 0
    Workbook_AddinInstall
End Sub

