Tag: excel display userform next to active cell

Place A Userform Next To The Clicked Cell

It may be more useful to display this userform next to the active cell that was clicked, rather than in the center of the sheet.

By declaring the GetDeviceCaps , GetDC , ReleaseDC

functions , I repositioned the userform next to each the clicked

activecell .(The template is checked in 32-bit and 64-bit Excel versions .)

“Type POINTAPI

X As Long

Y As Long

End Type

#If VBA7 Then

Declare PtrSafe Function GetDeviceCaps Lib “gdi32” (ByVal hDc As LongPtr, ByVal nIndex As Long) As Long

Declare PtrSafe Function GetDC Lib “user32” (ByVal hwnd As LongPtr) As LongPtr

Declare PtrSafe Function ReleaseDC Lib “user32” (ByVal hwnd As LongPtr, ByVal hDc As LongPtr) As Long

Dim hDc As LongPtr

#Else

Declare Function GetDeviceCaps Lib “gdi32” (ByVal hDc As Long, ByVal nIndex As Long) As Long

Declare Function GetDC Lib “user32” (ByVal hwnd As Long) As Long

Declare Function ReleaseDC Lib “user32” (ByVal hwnd As Long, ByVal hDc As Long) As Long

Dim hDc As Long

#End If

📥 Read more & download sample file