Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1352to1356
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Stoppuhr in Excel VBA

Stoppuhr in Excel VBA
24.03.2014 11:52:07
Georg
Hallo
Ich habe soeben von Windows XP auf Windows 8 gewechselt. Vorher und jetzt hatte ich Excel 2010. _ Ich hatte dort auf Windows XP folgendes VBA-Skript installiert - Stopphur in Excel: http://www.online-excel.de/excel/singsel_vba.php?f=96 - es funktinierte immer einwandfrei. Jetzt wollte ich auf dem neuen PC mit Windows 8 die xlam Datei wieder als Add-in installieren. Das funktionierte nicht, schliesslich habe ich Declare PtrSafe ergänzt (siehe unten), wie ich irgendwo gelesen hatte, damit's auf Windows 8 x64 funktioniert. Nun aber kommt immer eine Fehlermeldung: Fehler beim Kompilieren, Typen unverträglich, dabei werden die Zeilen unten markiert:

Private Sub prc_Start() und AddressOf prc_Display
Kann mir jemand helfen? Ich habe praktisch keine Ahnung von VBA-Programmierungen, deshalb bin  _
ich froh um jede verständliche Hilfe! Danke schon jetzt!
'  Modul:  basClock  Typ = Allgemeines Modul
Option Explicit
Option Private Module
'   Code Max Kaffl 2005
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function SetTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare PtrSafe Function KillTimer Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Declare PtrSafe Function timeGetTime Lib "winmm.dll" () As Long
Public lnghWnd As Long
Private lngStartTime As Long, lngPauseTime As Long
Private lngPresetTime As Long
Private blnPause As Boolean


Private Sub prc_Start()
Dim intIndex As Integer lngStartTime = timeGetTime - lngPresetTime With Application .MacroOptions Macro:="prc_Lap", _ HasShortcutKey:=True, ShortcutKey:="y" .OnDoubleClick = "prc_Lap" End With blnPause = False lngPresetTime = 0 objCommandBarButton(0).Enabled = False For intIndex = 1 To 4 objCommandBarButton(intIndex).Enabled = True Next objCommandBarButton(6).Enabled = False lnghWnd = FindWindow("XLMAIN", Application.Caption) SetTimer lnghWnd, 0, 1, AddressOf prc_Display End Sub

Public Sub prc_Lap()
ActiveCell.Value = fnc_strTime(timeGetTime - lngStartTime)
ActiveCell.Offset(1, 0).Select
End Sub

Private Sub prc_Pause()
If blnPause Then
lngStartTime = lngStartTime + (timeGetTime - lngPauseTime)
objCommandBarButton(3).Enabled = True
SetTimer lnghWnd, 0, 1, AddressOf prc_Display
Else
lngPauseTime = timeGetTime
objCommandBarButton(3).Enabled = False
KillTimer lnghWnd, 0
objCommandBarButton(5).Caption = fnc_strTime(timeGetTime - lngStartTime)
End If
blnPause = Not blnPause
End Sub

Private Sub prc_Stop()
Dim intIndex As Integer
If blnPause Then _
lngStartTime = lngStartTime + (timeGetTime - lngPauseTime)
ActiveCell.Value = fnc_strTime(timeGetTime - lngStartTime)
KillTimer lnghWnd, 0
For intIndex = 1 To 3
objCommandBarButton(intIndex).Enabled = False
Next
objCommandBarButton(5).Caption = ActiveCell.Text
ActiveCell.Offset(1, 0).Select
End Sub

Private Sub prc_Reset()
Dim intIndex As Integer
KillTimer lnghWnd, 0
lngStartTime = 0
objCommandBarButton(0).Enabled = True
For intIndex = 1 To 4
objCommandBarButton(intIndex).Enabled = False
Next
objCommandBarButton(5).Caption = "00:00:00,000"
objCommandBarButton(6).Enabled = True
With Application
.MacroOptions Macro:="prc_Lap", _
HasShortcutKey:=True, ShortcutKey:=""
.OnDoubleClick = ""
End With
End Sub

Private Sub prc_Preset()
Dim vntInput As Variant
Do
vntInput = InputBox("Vorgebezeit im Format hh:mm:ss eingeben.", _
"Eingabe", "00:00:00")
If StrPtr(vntInput) = 0 Then Exit Sub
If vntInput Like "##:##:##" And IsDate(vntInput) Then Exit Do
MsgBox "Fehlerhafte Eingabe.", 48, "Hinweis"
Loop
lngPresetTime = CDbl(CDate(vntInput)) * 86400000
objCommandBarButton(5).Caption = fnc_strTime(lngPresetTime)
End Sub

Private Sub prc_Display(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
objCommandBarButton(5).Caption = fnc_strTime(timeGetTime - lngStartTime)
End Sub

Private Function fnc_strTime(ByVal lngTime As Long) As String
Dim lngHour As Long, lngMinute As Long, lngSecond As Long
lngHour = lngTime \ 3600000
lngMinute = (lngTime Mod 3600000) \ 60000
lngSecond = (lngTime Mod 3600000 Mod 60000) \ 1000
lngTime = lngTime Mod 3600000 Mod 60000 Mod 1000
fnc_strTime = Format(CStr(lngHour), "00") & ":" & _
Format(CStr(lngMinute), "00") & ":" & _
Format(CStr(lngSecond), "00") & "," & _
Format(CStr(lngTime), "000")
End Function

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Stoppuhr in Excel VBA
24.03.2014 12:24:43
Tino
Hallo,
so viel erfahrung habe ich mit dem 64bit System auch nicht.
Hier findest Du wie die Deklarierung der API Funktionen ausehen muss.
http://www.jkp-ads.com/articles/apideclarations.asp
z. Bsp. aus
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
wird
Private Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Evtl. dies über die bedingte Kompilierung einbauen.
Gruß Tino

Anzeige
AW: Stoppuhr in Excel VBA
24.03.2014 13:35:20
Georg
Hallo Tino
Ich habe sämtliche "As Long" ersetzt durch "As LongPtr" - und es hat funktioniert! Riesigen Dank an dich für die rasche und schnelle Hilfe!

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige