Fout 400 bij userform op de taakbalk (modaal weergeven)

Status
Niet open voor verdere reacties.

rvisser1988

Gebruiker
Lid geworden
24 aug 2011
Berichten
31
Besten,

Ik ben nu al een poosje bezig om mijn userform netjes op de taakbals te krijgen, zodat ik Excel mooi kan sluiten.

Na veel zoeken is deze code om dit enkel voor het hoofduserform toe te passen deze (uiteraard niet mijn eigen geschreven code:d):

Code:
 'Windows API calls
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function EnableWindow Lib "user32" ( _
ByVal hWnd As Long, _
ByVal fEnable As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function SetFocus Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" ( _
ByVal hWndLock As Long) As Long
 
 'Window styles
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const GWL_EXSTYLE As Long = (-20) 'The offset of a window's extended style
Private Const WS_CAPTION As Long = &HC00000 'Style to add a titlebar
Private Const WS_SYSMENU As Long = &H80000 'Style to add a system menu
Private Const WS_MINIMIZEBOX As Long = &H20000 'Style to add a Minimize box on the title bar
Private Const WS_MAXIMIZEBOX As Long = &H10000 'Style to add a Maximize box to the title bar
Private Const WS_EX_APPWINDOW As Long = &H40000 'Application Window: shown on taskbar
Private Const WS_EX_TOOLWINDOW As Long = &H80 'Tool Window: small titlebar
 
 'Hide or show a window
Private Const SW_HIDE As Long = 0
Private Const SW_SHOW As Long = 5
 
 'Windows messages
Private Const WM_SETICON = &H80
 
Private hWnd As Long

Public Sub Userform_Initialize()

     'Get the userform's window handle
    If Val(Application.Version) < 9 Then
         
        hWnd = FindWindow("ThunderXFrame", Me.Caption) 'XL97
    Else
         
        hWnd = FindWindow("ThunderDFrame", Me.Caption) 'XL2000+
    End If
         
    SendMessage hWnd, WM_SETICON, True, 0
    SendMessage hWnd, WM_SETICON, False, 0
         
    LockWindowUpdate hWnd
    EnableWindow FindWindow("XLMAIN", Application.Caption), True
    ShowWindow hWnd, SW_HIDE 'Hide the form
         
    lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_CAPTION Or WS_SYSMENU Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
    SetWindowLong hWnd, GWL_STYLE, lStyle
         
    lStyle = GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW And Not WS_EX_TOOLWINDOW
    SetWindowLong hWnd, GWL_EXSTYLE, lStyle
         
    DrawMenuBar hWnd
    SetFocus hWnd
         
    ShowWindow hWnd, SW_SHOW 'Reshow the userform
         
    LockWindowUpdate 0& 'Unfreeze the form
         
     'Set the Excel window's enablement to the correct choice
    EnableWindow FindWindow("XLMAIN", Application.Caption), 1

End Sub

Nu krijg ik alleen telkens de foutmelding: Fout 400 tijdens de uitvoering. Het formulier wordt al weergegeven, en kan niet modaal worden weergegeven.

Ik heb al dagen zitten zoeken wat precies modaal is en hoe ik het uit deze code kan krijgen. Ik heb ook al tal zal andere codes geprobeerd, maar die geven over het algemeen allemaal foutmeldingen in het hoofdscript van de userform.

Ik hoop dat het op te lossen is en hoor graag jullie reacties.

Mijn dank is in ieder geval groot!!!
 
Laatst bewerkt:
Ik heb geen flauw idee hoe het gaat om een Userform op de taakbalk te plaatsen, maar in de eigenschappen van het form kun je 'ShowModal' op 'false of true' zetten.

Normaal gebruik ik 'showmodal=false' om toch nog in de cellen van het werkblad te kunnen werken als het form actief is.
 
Dank je voor je reactie.

Ik heb er een beetje mee lopen klooien, maar het is niet gelukt.

Ik heb nu de code van http://cellmasters.net/cd_063.htm geïmplementeerd en de bovenste regel 'Option Explecit' weggehaald, waardoor ik foutmeldingen verderop in het script teniet doe.

Wat mij betreft opgelost :)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan