Excel Useform: gewusst Wie: ausblenden der Anwendung, sondern haben-Symbol in der Taskleiste

Was ich haben will, ist Application.Sichtbar = False, so dass meine Benutzer nicht sehen können, die excel-Arbeitsblätter, nur das userform.

Ich habe dies funktioniert mit diesem code:

Private Sub Workbook_Open()
Application.Visible = False
UserForm2.Show
End Sub

Allerdings hat das nur die userform schwebend im hintergrund herum. Meine Benutzer haben andere Anwendungen geöffnet sind, und ich möchte, dass Sie ganz einfach ändern, um die userform, indem er ein Symbol auf der Taskleiste.

Fand ich, dass das folgende Beispiel online, aber ich kann nicht scheinen, um herauszufinden, wo dieser code. Noch ganz neu hier, also hoffentlich habe ich den richtigen code für den job. Wenn ich das Tue, kann jemand reden, der mir durch, wo es zu platzieren, wie es funktioniert nicht wenn ich es einfügen in meinen code?

(also sollte es gehen, unter "userform" oder "diese Arbeitsmappe: Erklärungen' etc. )

Danke,

Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_CAPTION As Long = &HC00000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_POPUP As Long = &H80000000
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_EX_DLGMODALFRAME As Long = &H1
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const SW_SHOW As Long = 5

Private Sub UserForm_Activate()
Application.Visible = False
Application.VBE.MainWindow.Visible = False
    Dim lngHwnd As Long
    Dim lngCurrentStyle As Long, lngNewStyle As Long
    If Val(Application.Version) < 9 Then
        lngHwnd = FindWindow("ThunderXFrame", Me.Caption)  'XL97
    Else
        lngHwnd = FindWindow("ThunderDFrame", Me.Caption)  'XL2000, XP, 2003?
    End If
    'Set the Windows style so that the userform has a minimise and maximise button
    lngCurrentStyle = GetWindowLong(lngHwnd, GWL_STYLE)
    lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
    lngNewStyle = lngNewStyle And Not WS_VISIBLE And Not WS_POPUP
    SetWindowLong lngHwnd, GWL_STYLE, lngNewStyle

    'Set the extended style to provide a taskbar icon
    lngCurrentStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
    lngNewStyle = lngCurrentStyle Or WS_EX_APPWINDOW
    SetWindowLong lngHwnd, GWL_EXSTYLE, lngNewStyle
    ShowWindow lngHwnd, SW_SHOW
End Sub
Private Sub UserForm_Terminate()
Application.Visible = True
End Sub

InformationsquelleAutor Ali Lumsden | 2014-07-14

Schreibe einen Kommentar