Option Explicit
Private WithEvents GB_CbE As CommandBarEvents
Private WithEvents Big5_CbE As CommandBarEvents
________________________________________
Private Sub Workbook_Open()
CreateVBEMenu
End Sub
________________________________________
Private Sub Workbook_AddinInstall()
Dim AI As AddIn, hWnd As Long
On Error Resume Next
hWnd = Application.VBE.MainWindow.hWnd
If Err.Number = 1004 Then
MsgBox "您的安全性設定不允許您執行此程序." _
& vbCrLf & vbCrLf & "請更改安全性設定後重新執行:" _
& vbCrLf & vbCrLf & " 1. 點選 工具 - 巨集 - 安全性." _
& vbCrLf & " 2. 點選 '信任存取 Visual Basic 專案"
On Error Resume Next
For Each AI In Application.AddIns
If AI.Name = ThisWorkbook.Name Then
AI.Installed = False
ThisWorkbook.Close False
End If
Next AI
End If
End Sub
________________________________________
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.VBE.CommandBars("cmd_TCSC").Delete
Application.VBE.CommandBars(2).Left = 0
End Sub
________________________________________
Sub CreateVBEMenu()
Dim vcbr As CommandBar, vctl As CommandBarControl
'如果 cmd_TCSC存在的話,刪除它
On Error Resume Next
Application.VBE.CommandBars("cmd_TCSC").Delete
Set vcbr = Application.VBE.CommandBars.Add(Name:="cmd_TCSC", _
Position:=msoBarTop, temporary:=True)
'新增Button
vcbr.Visible = True
vcbr.RowIndex = Application.VBE.CommandBars(2).RowIndex
Set vctl = vcbr.Controls.Add(Type:=msoControlButton)
With vctl
ThisWorkbook.Sheets("icon").Shapes("TCSC").Copy
.PasteFace
.Style = msoButtonIcon
.TooltipText = "繁轉簡"
Set GB_CbE = Application.VBE.Events.CommandBarEvents(.Control)
End With
Set vctl = vcbr.Controls.Add(Type:=msoControlButton)
With vctl
ThisWorkbook.Sheets("icon").Shapes("SCTC").Copy
.PasteFace
.Style = msoButtonIcon
.TooltipText = "簡轉繁"
Set Big5_CbE = Application.VBE.Events.CommandBarEvents(.Control)
End With
End Sub
________________________________________
Private Sub GB_CbE_Click(ByVal CommandBarControl As Object, _
handled As Boolean, CancelDefault As Boolean)
Call BIG5_GB
End Sub
________________________________________
Private Sub Big5_CbE_Click(ByVal CommandBarControl As Object, _
handled As Boolean, CancelDefault As Boolean)
Call GB_BIG5
End Sub