|
>hoge.xls:1,hoge.xls:2
>のようにしているとき
>ブックの×ボタンで閉じられないようにしたいと思っていますが
>上記に相当するイベントは無いようです
>
>(複数ウインドウ時 hoge.xls:1,hoge.xls:2 の場合の、1方を閉じるときです)
常に2つのWindowを左右並べで整列させて、片方を閉じさせないという意味でしょうか?
かん違いしていなければ、閉じた場合強制で復活させて整列し直す、という対応でも良い?
'ThisWorkbookModule
Option Explicit
Private bk_close As Boolean
'-----------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
bk_close = True
End Sub
'-----------------------------------------------------------
Private Sub Workbook_Open()
test1
End Sub
'-----------------------------------------------------------
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
If Not bk_close Then
Application.OnTime Now, Me.CodeName & ".wnChk"
End If
End Sub
'-----------------------------------------------------------
Sub wnChk()
If Me.Windows.Count <> 2 Then
test1
End If
End Sub
'-----------------------------------------------------------
Sub test1()
Dim max_h As Double
Dim max_w As Double
Dim count_w As Long
Dim i As Long
Application.EnableEvents = False
With Me
count_w = .Windows.Count
If count_w > 2 Then
For i = count_w To 3 Step -1
.Windows(i).Close
Next
ElseIf count_w = 1 Then
.NewWindow
End If
With .Windows(1)
.WindowState = xlMaximized
max_h = .Height - 20.25 'なぜか-20.25 必要
max_w = .Width
.WindowState = xlNormal
.Top = 1
.Left = 1
.Height = max_h
'.Width = 300
.Width = 140
.Caption = "メイン"
End With
With .Windows(2)
.Top = 1
'.Left = 300
.Left = 142
.Height = max_h
'.Width = max_w - 300
.Width = max_w - 142
.Caption = "サブ"
End With
End With
Application.EnableEvents = True
End Sub
|
|