Hallo,
probier mal, füg Deine UserForm mit einem CommandButton beliebig auf der Form platziert in Deine Mappe ein, dann Code in folgende drei Module:
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliSeconds As Long)
Private mdtmTime As Date
Private mblnClick As Boolean
Private Sub CommandButton1_Click()
Call Application.OnTime(EarliestTime:=mdtmTime, _
Procedure:="prcTimer", Schedule:=False)
mblnClick = True
Call Unload(Object:=Me)
End Sub
Private Sub UserForm_Activate()
Dim lngIndex As Long
With Controls.Add(bstrProgID:="MSComctlLib.ProgCtrl.2", _
Name:="ProgressBar1", Visible:=True)
.Left = 20
.Top = 20
.Width = 150
.Height = 30
.Max = 10
.Min = 0
.Value = 0
End With
With CommandButton1
.Width = 100
.Height = 20
.Top = Controls("ProgressBar1").Top + Controls("ProgressBar1").Height
.Left = Controls("ProgressBar1").Left
.Caption = "Cancel_Close"
.BackColor = &H9400D3
End With
mdtmTime = Now + TimeSerial(0, 0, 10)
Call Application.OnTime(EarliestTime:=mdtmTime, Procedure:="prcTimer")
With Controls("ProgressBar1")
For lngIndex = .Min To .Max
DoEvents
Call Sleep(1000&)
Call .Refresh
Call Repaint
.Value = lngIndex
If Not mblnClick Then _
Caption = "Datei wird geschlossen in " & _
.Max - lngIndex & " Sec"
Next
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = CloseMode <> vbFormCode
End Sub
' **********************************************************************
' Modul: DieseArbeitsmappe Typ: Klassenmodul der Arbeitsmappe
' **********************************************************************
Option Explicit
Private Sub Workbook_Open()
If Not ReadOnly Then _
Call Application.OnTime(EarliestTime:=Now + TimeSerial(0, 0, 30), Procedure:="prcTimer")
End Sub
' **********************************************************************
' Modul: Modul1 Typ: Standardmodul
' **********************************************************************
Option Explicit
Option Private Module
Public Sub prcTimer()
Static sblnInit As Boolean
If sblnInit Then
Call ThisWorkbook.Save
Call Application.Quit
Else
sblnInit = True
Call UserForm1.Show
End If
End Sub
Gruß,
|