Option Explicit
Private Withevents Excel As Application, IdxFeui As Long
Private Sub UserForm_Initialize()
Set Excel = Application
End Sub
Private Sub Excel_WorkbookActivate(ByVal Wb As Workbook)
If Wb.Name = ThisWorkbook.Name Then
Me.Show
Excel_SheetActivate Wb.ActiveSheet
Else
Me.Hide: End If
End Sub
Private Sub Excel_SheetActivate(ByVal Sh As Object)
If Not Me.Visible Then Exit Sub
IdxFeui = Sh.Index
End Sub