superstan2310
New Member
- Joined
- Nov 3, 2024
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
Hi All,
Currently working on a project and I'm trying to get a button located in the bottom right of the application window at all times, and staying there, even if the sheet is scrolled up/down/left/right or if the application window is moved.
I have created a userform (which just contains a command button) and added the below code into it as of this moment, and functionally it is everything I need, except for that fact that the button appears with a title bar, a close button, and can be moved by the user when dragging the title bar. Qualities that I do not wish it to have.
I have seen videos and forum threads about hiding the title bar (and therefore the close button, and prevents people moving it), which clearly shows it is possible, however when I copy the code they use and incorporate it into mine one of three things happen:
1. It outright doesn't do anything.
2. It creates a white box (the size of the userform) in the middle of the screen that just blocks the view of anything beneath it.
3. It stops my code below from working.
There is a bit of code left out of the below, but that is just code in the "ThisWorkbook" section for creating a modeless userform on workbook open, and calling the SetPos macro when the window is resized.
Would anyone be able to help with keeping the functionality of the below code, while being able to remove the title bar? If the code has to be rewritten from scratch, I don't mind.
Currently working on a project and I'm trying to get a button located in the bottom right of the application window at all times, and staying there, even if the sheet is scrolled up/down/left/right or if the application window is moved.
I have created a userform (which just contains a command button) and added the below code into it as of this moment, and functionally it is everything I need, except for that fact that the button appears with a title bar, a close button, and can be moved by the user when dragging the title bar. Qualities that I do not wish it to have.
I have seen videos and forum threads about hiding the title bar (and therefore the close button, and prevents people moving it), which clearly shows it is possible, however when I copy the code they use and incorporate it into mine one of three things happen:
1. It outright doesn't do anything.
2. It creates a white box (the size of the userform) in the middle of the screen that just blocks the view of anything beneath it.
3. It stops my code below from working.
There is a bit of code left out of the below, but that is just code in the "ThisWorkbook" section for creating a modeless userform on workbook open, and calling the SetPos macro when the window is resized.
Would anyone be able to help with keeping the functionality of the below code, while being able to remove the title bar? If the code has to be rewritten from scratch, I don't mind.
VBA Code:
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByRef hWnd As LongPtr) As Long
Private Declare PtrSafe Function SetParent Lib "user32" (ByVal hWndChild As LongPtr, ByVal hWndNewParent As LongPtr) As LongPtr
Private hWndForm As LongPtr, WbHwnd As LongPtr
#Else
Private Declare Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByRef hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private hWndForm As Long, WbHwnd As Long
#End If
Private Sub UserForm_Activate()
WbHwnd = Application.hWnd
Call IUnknown_GetWindow(Me, hWndForm)
Call SetParent(hWndForm, WbHwnd)
Call SetPos
End Sub
Public Sub SetPos()
Me.StartUpPosition = 0
Me.Left = Application.Width - 150 - Application.Left
Me.Top = Application.Height - 125
End Sub