Réduire un Userform dans barre de tâche
Bonjour,
ma macro se compose d'une Userform1 avec des boutons pour:
- l'importation de feuilles issues d'un autre classeur.
- l'exportation de feuilles dans d'autre classeur après traitement des données (manuelle ou non) --> si jamais vous avez une idée également https://forum.excel-pratique.com/excel/listbox-pour-selectionner-les-feuilles-a-enregistrer-separemm...
- d'autres fonctions à venir (parce que les macros c'est trop cool et ça fait gagner du temps quand on y arrive...)
Le Userform doit s'ouvrir au lancement du fichier Excel mais pas forcément besoin de l'utiliser si on veux juste parcourir le fichier
J'avais utilisé ceci afin qu'elle soit visible mais pas forcément active (code dans ThisWorkbook):
Private Sub Workbook_Open()
UserForm1.Show False
End SubPour améliorer ceci, car la fenêtre prend de plus en plus de place sur l'écran au fur et à mesure des améliorations et ajout de fonction, je souhaiterais pouvoir réduire la fenêtre dans la barre de tache et pouvoir la réafficher quand j'en ai besoin.
J'ai trouvé ce post : https://forum.excel-pratique.com/astuces/boutons-reduire-et-agrandir-dans-un-userform-69474
Mais ça ne fonctionne pas chez moi !
J'ai vu que j'étais en 64 bits donc j'ai bien pris le code correspondant, cependant, lors de l'ouverture du fichier Excel le message suivant apparait :
J'ai supprimé le code dans ThisWorkbook mais cela ne vient pas de là.
Quelqu'un a une piste ?
merci d'avance
Bonjour CDU3390
Voici le fichier comme il devrait fonctionner
@+
Bonjour,
Dans le module1 de BrunoM (salutations au passage), remplacez le code par celui-ci (juste pour un test que je veux réaliser depuis... Pfff... Longtemps!)
Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLong As LongPtr) As LongPtr
Private Declare PtrSafe Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As LongPtr) As LongPtr
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private hWnd As LongPtr, IStyle As LongPtr
Public Sub BoutonUSF(F As Object)
hWnd = FindWindow(vbNullString, F.Caption)
IStyle = GetWindowLong(hWnd, GWL_STYLE) Or &H70000
SetWindowLong hWnd, GWL_STYLE, IStyle
End SubPrécisions :
1- Les LongPtr ne sont pas utiles partout (uniquement pour les Handle de fenêtre), je proposerai un second test si celui-ci fonctionne,
2- cela fonctionne tel quel sur 32 bits.
En fait, j'explique le pourquoi de mon test...
La principale différence entre le 64 bits et le 32 bits réside dans la déclaration des Long affectés aux Handle et autres pointeurs.
En 32 bits, ils sont déclarés As Long (car 4 octets suffisent en 32 bits), en 64 bits, ils sont déclarés LongLong (car nécessitent 8 octets en 64 bits).
Or, il existe un format "intermédiaire", ou plutôt de conversion, le LongPtr.
Pour le coup, si ce n'était que de faire la différence entre Long et LongLong, il suffirait d'employer LongPtr systématiquement, déclarer l'API SafePtr systématiquement (quelque soit la version 32 ou 64 bits), et pouf pouf on serait tranquille.
Mais visiblement, outre cette petite différence, pour certaines fonctions de l'api (et pas toutes, bravo MS), ils ont changé les noms des fonctions (alias dans les déclarations) au sein même des librairies.
Ainsi, dans la lib User32, ils ont rebaptisé "SetWindowLongA" (32 bits) en "SetWindowLongPtrA"(64 bits)... Pfff.
Donc, il faut tenter des petites modifications comme celle-ci :
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetWindowLong Lib "User32" Alias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As LongPtr) As LongPtr
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private hWnd As LongPtr, IStyle As LongPtr
Public Sub BoutonUSF(F As Object)
hWnd = FindWindow(vbNullString, F.Caption)
IStyle = GetWindowLong(hWnd, GWL_STYLE) Or &H70000
SetWindowLong hWnd, GWL_STYLE, IStyle
End SubOn avance. Si si, on avance...
Re,
il faut croire que ce n'est pas aussi simple pour tout le monde.
En réponse à Bruno, non je ne suis pas sur Mac.
Pour la réponse de Pijaku, en remplaçant le code par ce dernier, il ne trouve le point d'entrée FindWindow maintenant.
Est-ce que je dois faire le meme principe de boucle If que pour SetWindow qui à l'air lui de fonctonner ?
CDU3390
Ce qui est étonnant c'est que le code utilises des DLL Windows, donc logiquement il n'y a pas de raison que ça ne fonctionne pas
Il faudrait peut-être vérifier vos fichier système
Pour ça, il faut lancer l'interpréteur de commande en mode administrateur
et saisir la commande
sfc /scannowA voir
Bon je viens de tester sur un autre ordi (perso pas pro) et effectivement ça fonctionne
Il est équipé de Office 365 celui là !
Savez-vous comment faire pour identifier les différences de configuration ?
Re,
Ce n'est pas un problème de version d'Office, mais de Windows et de fichier système
ah
ca ne va pas être simple à résoudre ça tiens !
Salut,
On peut essayer quelque chose de facile.
> Tu vas dans C:\Windows
> Tu recherches : user32.dll
> Clic droit sur ce fichier / ouvrir avec
> Choisit le bloc notes
> Rechercher (Ctrl + F) : FindWindow
Dans tout le charabia que tu auras sous les yeux, il devrait trouver le "titre" de ta fonction, titre à utiliser dans son appel.
Exemple chez moi :
USER32.dll GetPointerFrameArrivalTimes Wow64Transition ActivateKeyboardLayout AddClipboardFormatListener AddVisualIdentifier AdjustWindowRect AdjustWindowRectEx AdjustWindowRectExForDpi AlignRects AllowForegroundActivation AllowSetForegroundWindow AnimateWindow AnyPopup AppendMenuA AppendMenuW AreDpiAwarenessContextsEqual ArrangeIconicWindows AttachThreadInput BeginDeferWindowPos BeginPaint BlockInput BringWindowToTop BroadcastSystemMessage BroadcastSystemMessageA BroadcastSystemMessageExA BroadcastSystemMessageExW BroadcastSystemMessageW BuildReasonArray CalcMenuBar CalculatePopupWindowPosition CallMsgFilter CallMsgFilterA CallMsgFilterW CallNextHookEx CallWindowProcA CallWindowProcW CancelShutdown CascadeChildWindows CascadeWindows ChangeClipboardChain ChangeDisplaySettingsA ChangeDisplaySettingsExA ChangeDisplaySettingsExW ChangeDisplaySettingsW ChangeMenuA ChangeMenuW ChangeWindowMessageFilter ChangeWindowMessageFilterEx CharLowerA CharLowerBuffA CharLowerBuffW CharLowerW CharNextA CharNextExA CharNextW CharPrevA CharPrevExA CharPrevW CharToOemA CharToOemBuffA CharToOemBuffW CharToOemW CharUpperA CharUpperBuffA CharUpperBuffW CharUpperW CheckBannedOneCoreTransformApi CheckDBCSEnabledExt CheckDlgButton CheckMenuItem CheckMenuRadioItem CheckProcessForClipboardAccess CheckProcessSession CheckRadioButton CheckWindowThreadDesktop ChildWindowFromPoint ChildWindowFromPointEx CliImmSetHotKey ClientThreadSetup ClientToScreen ClipCursor CloseClipboard CloseDesktop CloseGestureInfoHandle CloseTouchInputHandle CloseWindow CloseWindowStation ConsoleControl ControlMagnification CopyAcceleratorTableA CopyAcceleratorTableW CopyIcon CopyImage CopyRect CountClipboardFormats CreateAcceleratorTableA CreateAcceleratorTableW CreateCaret CreateCursor CreateDCompositionHwndTarget CreateDesktopA CreateDesktopExA CreateDesktopExW CreateDesktopW CreateDialogIndirectParamA CreateDialogIndirectParamAorW CreateDialogIndirectParamW CreateDialogParamA CreateDialogParamW CreateIcon CreateIconFromResource CreateIconFromResourceEx CreateIconIndirect CreateMDIWindowA CreateMDIWindowW CreateMenu CreatePopupMenu CreateSyntheticPointerDevice CreateSystemThreads CreateWindowExA CreateWindowExW CreateWindowInBand CreateWindowInBandEx CreateWindowIndirect CreateWindowStationA CreateWindowStationW CsrBroadcastSystemMessageExW CtxInitUser32 DdeAbandonTransaction DdeAccessData DdeAddData DdeClientTransaction DdeCmpStringHandles DdeConnect DdeConnectList DdeCreateDataHandle DdeCreateStringHandleA DdeCreateStringHandleW DdeDisconnect DdeDisconnectList DdeEnableCallback DdeFreeDataHandle DdeFreeStringHandle DdeGetData DdeGetLastError DdeGetQualityOfService DdeImpersonateClient DdeInitializeA DdeInitializeW DdeKeepStringHandle DdeNameService DdePostAdvise DdeQueryConvInfo DdeQueryNextServer DdeQueryStringA DdeQueryStringW DdeReconnect DdeSetQualityOfService DdeSetUserHandle DdeUnaccessData DdeUninitialize DefDlgProcA NTDLL.NtdllDialogWndProc_A DefDlgProcW NTDLL.NtdllDialogWndProc_W DefFrameProcA DefFrameProcW DefMDIChildProcA DefMDIChildProcW DefRawInputProc DefWindowProcA NTDLL.NtdllDefWindowProc_A DefWindowProcW NTDLL.NtdllDefWindowProc_W DeferWindowPos DeferWindowPosAndBand DelegateInput DeleteMenu DeregisterShellHookWindow DestroyAcceleratorTable DestroyCaret DestroyCursor DestroyDCompositionHwndTarget DestroyIcon DestroyMenu DestroyReasons DestroySyntheticPointerDevice DestroyWindow DialogBoxIndirectParamA DialogBoxIndirectParamAorW DialogBoxIndirectParamW DialogBoxParamA DialogBoxParamW DisableProcessWindowsGhosting DispatchMessageA DispatchMessageW DisplayConfigGetDeviceInfo DisplayConfigSetDeviceInfo DisplayExitWindowsWarnings DlgDirListA DlgDirListComboBoxA DlgDirListComboBoxW DlgDirListW DlgDirSelectComboBoxExA DlgDirSelectComboBoxExW DlgDirSelectExA DlgDirSelectExW DoSoundConnect DoSoundDisconnect DragDetect DragObject DrawAnimatedRects DrawCaption DrawCaptionTempA DrawCaptionTempW DrawEdge DrawFocusRect DrawFrame DrawFrameControl DrawIcon DrawIconEx DrawMenuBar DrawMenuBarTemp DrawStateA DrawStateW DrawTextA DrawTextExA DrawTextExW DrawTextW DwmGetDxRgn DwmGetDxSharedSurface DwmGetRemoteSessionOcclusionEvent DwmGetRemoteSessionOcclusionState DwmKernelShutdown DwmKernelStartup DwmLockScreenUpdates DwmValidateWindow EditWndProc EmptyClipboard EnableMenuItem EnableMouseInPointer EnableNonClientDpiScaling EnableOneCoreTransformMode EnableScrollBar EnableSessionForMMCSS EnableWindow EndDeferWindowPos EndDeferWindowPosEx EndDialog EndMenu EndPaint EndTask EnterReaderModeHelper EnumChildWindows EnumClipboardFormats EnumDesktopWindows EnumDesktopsA EnumDesktopsW EnumDisplayDevicesA EnumDisplayDevicesW EnumDisplayMonitors EnumDisplaySettingsA EnumDisplaySettingsExA EnumDisplaySettingsExW EnumDisplaySettingsW EnumPropsA EnumPropsExA EnumPropsExW EnumPropsW EnumThreadWindows EnumWindowStationsA EnumWindowStationsW EnumWindows EqualRect EvaluateProximityToPolygon EvaluateProximityToRect ExcludeUpdateRgn ExitWindowsEx FillRect FindWindowA FindWindowExA FindWindowExW FindWindowW FlashWindow FlashWindowEx FrameRect FreeDDElParam FrostCrashedWindow GetActiveWindow GetAltTabInfo GetAltTabInfoA GetAltTabInfoW GetAncestor GetAppCompatFlags2 GetAppCompatFlags GetAsyncKeyState GetAutoRotationState GetAwarenessFromDpiAwarenessContext GetCIMSSM GetCapture GetCaretBlinkTime GetCaretPos GetClassInfoA GetClassInfoExA GetClassInfoExW GetClassInfoW GetClassLongA GetClassLongW GetClassNameA GetClassNameW GetClassWord GetClientRect GetClipCursor GetClipboardAccessToken GetClipboardData GetClipboardFormatNameA GetClipboardFormatNameW GetClipboardOwner GetClipboardSequenceNumber GetClipboardViewer GetComboBoxInfo GetCurrentInputMessageSource GetCursor GetCursorFrameInfo GetCursorInfo GetCursorPos GetDC GetDCEx GetDesktopID GetDesktopWindow GetDialogBaseUnits GetDialogControlDpiChangeBehavior GetDialogDpiChangeBehavior GetDisplayAutoRotationPreferences GetDisplayConfigBufferSizes GetDlgCtrlID GetDlgItem GetDlgItemInt GetDlgItemTextA GetDlgItemTextW GetDoubleClickTime GetDpiAwarenessContextForProcess GetDpiForMonitorInternal GetDpiForSystem GetDpiForWindow GetDpiFromDpiAwarenessContext GetExtendedPointerDeviceProperty GetFocus GetForegroundWindow GetGUIThreadInfo GetGestureConfig GetGestureExtraArgs GetGestureInfo GetGuiResources GetIconInfo GetIconInfoExA GetIconInfoExW GetInputDesktop GetInputLocaleInfo GetInputState GetInternalWindowPos GetKBCodePage GetKeyNameTextA GetKeyNameTextW GetKeyState GetKeyboardLayout GetKeyboardLayoutList GetKeyboardLayoutNameA GetKeyboardLayoutNameW GetKeyboardState GetKeyboardType GetLastActivePopup GetLastInputInfo GetLayeredWindowAttributes GetListBoxInfo GetMagnificationDesktopColorEffect GetMagnificationDesktopMagnification GetMagnificationDesktopSamplingMode GetMagnificationLensCtxInformation GetMenu GetMenuBarInfo GetMenuCheckMarkDimensions GetMenuContextHelpId GetMenuDefaultItem GetMenuInfo GetMenuItemCount GetMenuItemID GetMenuItemInfoA GetMenuItemInfoW GetMenuItemRect GetMenuState GetMenuStringA GetMenuStringW GetMessageA GetMessageExtraInfo GetMessagePos GetMessageTime GetMessageW GetMonitorInfoA GetMonitorInfoW GetMouseMovePointsEx GetNextDlgGroupItem GetNextDlgTabItem GetOpenClipboardWindow GetParent GetPhysicalCursorPos GetPointerCursorId GetPointerDevice GetPointerDeviceCursors GetPointerDeviceOrientation GetPointerDeviceProperties GetPointerDeviceRects GetPointerDevices GetPointerFrameInfo GetPointerFrameInfoHistory GetPointerFramePenInfo GetPointerFramePenInfoHistory GetPointerFrameTimes GetPointerFrameTouchInfo GetPointerFrameTouchInfoHistory GetPointerInfo GetPointerInfoHistory GetPointerInputTransform GetPointerPenInfo GetPointerPenInfoHistory GetPointerTouchInfo GetPointerTouchInfoHistory GetPointerType GetPriorityClipboardFormat GetProcessDefaultLayout GetProcessDpiAwarenessInternal GetProcessUIContextInformation GetProcessWindowStation GetProgmanWindow GetPropA GetPropW GetQueueStatus GetRawInputBuffer GetRawInputData GetRawInputDeviceInfoA GetRawInputDeviceInfoW GetRawInputDeviceList GetRawPointerDeviceData GetReasonTitleFromReasonCode GetRegisteredRawInputDevices GetScrollBarInfo GetScrollInfo GetScrollPos GetScrollRange GetSendMessageReceiver GetShellChangeNotifyWindow GetShellWindow GetSubMenu GetSysColor GetSysColorBrush GetSystemDpiForProcess GetSystemMenu GetSystemMetrics GetSystemMetricsForDpi GetTabbedTextExtentA GetTabbedTextExtentW GetTaskmanWindow GetThreadDesktop GetThreadDpiAwarenessContext GetThreadDpiHostingBehavior GetTitleBarInfo GetTopLevelWindow GetTopWindow GetTouchInputInfo GetUnpredictedMessagePos GetUpdateRect GetUpdateRgn GetUpdatedClipboardFormats GetUserObjectInformationA GetUserObjectInformationW GetUserObjectSecurity GetWinStationInfo GetWindow GetWindowBand GetWindowCompositionAttribute GetWindowCompositionInfo GetWindowContextHelpId GetWindowDC GetWindowDisplayAffinity GetWindowDpiAwarenessContext GetWindowDpiHostingBehavior GetWindowFeedbackSetting GetWindowInfo GetWindowLongA GetWindowLongW GetWindowMinimizeRect GetWindowModuleFileName GetWindowModuleFileNameA GetWindowModuleFileNameW GetWindowPlacement GetWindowProcessHandle GetWindowRect GetWindowRgn GetWindowRgnBox GetWindowRgnEx GetWindowTextA GetWindowTextLengthA GetWindowTextLengthW GetWindowTextW GetWindowThreadProcessId GetWindowWord GhostWindowFromHungWindow GrayStringA GrayStringW HandleDelegatedInput HideCaret HiliteMenuItem HungWindowFromGhostWindow IMPGetIMEA IMPGetIMEW IMPQueryIMEA IMPQueryIMEW IMPSetIMEA IMPSetIMEW ImpersonateDdeClientWindow InSendMessage InSendMessageEx InflateRect InheritWindowMonitor InitDManipHook InitializeGenericHidInjection InitializeInputDeviceInjection InitializeLpkHooks InitializePointerDeviceInjection InitializePointerDeviceInjectionEx InitializeTouchInjection InjectDeviceInput InjectGenericHidInput InjectKeyboardInput InjectMouseInput InjectPointerInput InjectSyntheticPointerInput InjectTouchInput InsertMenuA InsertMenuItemA InsertMenuItemW InsertMenuW InternalGetWindowIcon InternalGetWindowText IntersectRect InvalidateRect InvalidateRgn InvertRect IsCharAlphaA IsCharAlphaNumericA IsCharAlphaNumericW IsCharAlphaW IsCharLowerA IsCharLowerW IsCharUpperA IsCharUpper
Bonjour,
alors j'ai cherché le fichier user32.dll et j'en trouve plusieurs dans plusieurs dossier différent.
En cherchant à l'intérieur des 2 premiers je trouve les fonctions suivantes :
FindWindowA / FindWindowExA / FindWindowExW / FindWindowW / SetWindowLongA / SetWindowLongW / SetWindowLong / GetWindowLongA / GetWindowLongW
Mais en cherchant dans le troisième je trouve :
FindWindowA / FindWindowExA / FindWindowExW / FindWindowW / SetWindowLongA /SetWindowLongPtrA / SetWindowLongPtrW / SetWindowLongW / GetWindowLongA / GetWindowLongPtrA / GetWindowLongPtrW / GetWindowLongW
Pensez-vous que c'est normal ?
Comment savoir quel fichier est lié à Visual Basic VBA Excel ?
Tes fonctions surlignées de jaune sont tout ce qu'il y a de plus normal, en 64 bits.
Le fichier utilisé par Excel (de mémoire, sans connaitre le système 64 bits, je peux donc me tromper) est celui du System32.
Par contre, ce qui est inquiétant, c 'est que tu trouves bien FindWindowA, quelque soit la dll...
Le message d'erreur VBA est qu'il ne trouvait pas la fonction FindWindowA dans la dll. Or elle y figure bien.
Essaye juste ceci dans le module :
Private Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private hWnd As LongPtr
Public Sub BoutonUSF(F As Object)
hWnd = FindWindow(vbNullString, F.Caption)
End SubA tester également de refaire un userform, un module, dans un nouveau classeur tout neuf, tout vide...
Alors là, je ne vois pas de où vient ton problème.
Désolé.
et il n’existe pas une autre façon de réduire un USF?
Genre en cliquant sur un bouton, ça balance sur un autre USF plus petit placer en bas à gauche avec 1 seul bouton qui lorsqu’on clique dessus ré affiche le premier?
Moins orthodoxe mais je pense que ça doit se faire. Si je bloque de nouveau je reviendrais vers vous 😁



