Skip to content.

Sections
Personal tools
You are here: Home » コミュニティ » masarl memorial » homepage3.nifty.com » masarl » article » excel-decorator » SheetDecorator.txt

SheetDecorator.txt

Document Actions

VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "SheetDecorator" Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit

Public Parent As BookDecorator Public WithEvents Target As Worksheet

Public mnuDoCommand As CommandBarControl

Public Sub Initialize(aTarget As Worksheet, aParent As BookDecorator) Set Target = aTarget Set Parent = aParent OnFocus End Sub

Public Sub OnFocus() Set Parent.ActiveSheetDecorator = Me SetupMenus End Sub

Public Sub OnBlur() Set Parent.ActiveSheetDecorator = Nothing CleanupMenus End Sub

Public Sub SetupMenus() Set mnuDoCommand = Parent.Parent.Menu.Controls.Add(Type:=msoControlButton, Temporary:=True) With mnuDoCommand .Caption = "シートコマンド実行" .OnAction = "SheetDecoratorClass.DoCommand" End With End Sub

Public Sub CleanupMenus() If Not mnuDoCommand Is Nothing Then mnuDoCommand.Delete Set mnuDoCommand = Nothing End If End Sub

Public Sub DoCommand() With Target.Cells.Interior .ColorIndex = Int((50 - 1 + 1) * Rnd + 1) .Pattern = xlSolid End With End Sub

Private Sub Class_Terminate() OnBlur End Sub

Private Sub Target_Activate() OnFocus End Sub

Private Sub Target_Deactivate() OnBlur End Sub