VBA XL problem
Jeg forsøger at lave noget kode derfryser en form i excel når den bliver
opdateret. Det giver en bedre performance.
Jeg har dog lidt problemer med nogle
typedefinitioner jeg kan ikke få til
virke.
Det drejer sig om Dim obFF As New CFreezeform.
Der kommer en fejlmeddelelse om at den ikke
er defineret.
jeg har lavet en form med en listbox og to
knapper.
Følgende kode er under en class module ved navn CFreezeform.
Option Explicit
\'Find a window
Private Declare Function FindWindow Lib \"user32\" _
Alias \"FindWindowA\" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
\'Freeze the window to prevent continous redraws
Private Declare Function LockWindowUpdate Lib \"user32\" ( _
ByVal hwndLock As Long) As Long
Public Sub Freeze(oForm As UserForm)
Dim hWnd As Long
\'Get a handle to the userform window,
\'using the class name appropriate for the XL version.
If Val(Application.Version) >= 9 Then
hWnd = FindWindow(\"ThunderDFreame\", oForm.Caption)
Else
hWnd = FindWindow(\"ThunderFreame\", oForm.Caption)
End If
\' if you got the handle freeze the window.
If hWnd > 0 Then LockWindowUpdate hWnd
End Sub
\'allow the calling routine to unfreeze the userform
Public Sub UnFreeze()
LockWindowUpdate 0
End Sub
\'if they forget to unfreeze the form do it at the end
\'of the calling routine (when you go out of scope)
Private Sub Class_Terminate()
UnFreeze
End Sub
og følgende kode er under knappen:
Private Sub CommandButton2_Click()
Dim obFF As New CFreezeform, i As Integer
obFF.Freeze Me
For i = 1 To 1000
ListBox1.AddItem \"item\" & i
DoEvents
Next i
End Sub