01.03.2026, 13:24
Hallo zusammen brauche Hilfe !!!
Habe ein problem mit meiner userform scrollbar ich möchte sie ganz genau
über eine excel zelle positioniert haben und die scrollbar soll ganze ohne titelleiste sein
aber mit meinem code den ich benutze wird die scrollbar entweder auf meinem menüband angezeigt
oder wenn ich den code anpasse schon etwas dichter bei meiner zelle über die die scrollbar liegen soll
aber nicht genau darüber egal was ich mache der code findet die position nicht
habe es sschon mit pixel und points umrechnung probiert aber es funktioniert nicht
das ist der code den ich benutze:
Option Explicit
' --- API Funktionen ---
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 Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hWnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal uFlags As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hdc As LongPtr) As Long
Private Const GWL_STYLE As Long = -16
Private Const WS_CAPTION As Long = &HC00000
Private Const LOGPIXELSX As Long = 88
' --- Deine Einstellungen ---
Private Const SCHRITT As Double = 0.1
Private Const ZELLE_WERT As String = "F41"
Private Const ZELLE_OPTIK As String = "F40"
Private Const BLATT As String = "Blad1"
Private Sub UserForm_Initialize()
' Wert laden
Dim v As Variant
v = ThisWorkbook.Worksheets(BLATT).Range(ZELLE_WERT).Value
If IsNumeric(v) Then
On Error Resume Next
ScrollBar1.Value = CDbl(v) / SCHRITT
On Error GoTo 0
End If
End Sub
Private Sub UserForm_Activate()
Dim hWnd As LongPtr, hdc As LongPtr
Dim r As Range
Dim ScreenPPI As Long
Dim PointsToPixel As Double
Dim pLeft As Long, pTop As Long, pWidth As Long, pHeight As Long
Set r = ThisWorkbook.Worksheets(BLATT).Range(ZELLE_OPTIK)
hWnd = FindWindow("ThunderDFrame", Me.Caption)
' 1. Titelleiste entfernen
SetWindowLong hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) And Not WS_CAPTION
DrawMenuBar hWnd
' 2. Monitor-Skalierung erkennen
hdc = GetDC(0)
ScreenPPI = GetDeviceCaps(hdc, LOGPIXELSX)
ReleaseDC 0, hdc
PointsToPixel = ScreenPPI / 72
' 3. Position berechnen
' Wir nutzen PointsToScreenPixels und addieren einen kleinen Versatz,
' der bei fast allen Windows-Systemen durch den fehlenden Rahmen entsteht.
pLeft = ActiveWindow.PointsToScreenPixelsX(r.Left)
pTop = ActiveWindow.PointsToScreenPixelsY(r.Top)
' Die Größe muss bei 125%/150% Skalierung oft leicht korrigiert werden
' damit sie nicht zu klein wirkt:
pWidth = (r.Width * PointsToPixel)
pHeight = (r.Height * PointsToPixel)
' 4. Windows-Befehl: Position setzen
' Falls es immer noch minimal verschoben ist,
' ändere hier pLeft + 1 oder pTop + 1
SetWindowPos hWnd, 0, pLeft, pTop, pWidth, pHeight, &H40
' 5. ScrollBar anpassen
With ScrollBar1
.Move 0, 0, Me.InsideWidth, Me.InsideHeight
.Min = 0
.Max = 1000
End With
End Sub
' --- Steuerung ---
Private Sub ScrollBar1_Scroll(): Update: End Sub
Private Sub ScrollBar1_Change(): Update: End Sub
Private Sub Update()
On Error Resume Next
ThisWorkbook.Worksheets(BLATT).Range(ZELLE_WERT).Value = ScrollBar1.Value * SCHRITT
On Error GoTo 0
End Sub
Frage kann mir bitte jemand helfen bei diesem problem
wäre super wenn mir jemand helfen könnte
Habe ein problem mit meiner userform scrollbar ich möchte sie ganz genau
über eine excel zelle positioniert haben und die scrollbar soll ganze ohne titelleiste sein
aber mit meinem code den ich benutze wird die scrollbar entweder auf meinem menüband angezeigt
oder wenn ich den code anpasse schon etwas dichter bei meiner zelle über die die scrollbar liegen soll
aber nicht genau darüber egal was ich mache der code findet die position nicht
habe es sschon mit pixel und points umrechnung probiert aber es funktioniert nicht
das ist der code den ich benutze:
Option Explicit
' --- API Funktionen ---
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 Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hWnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal uFlags As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hdc As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hWnd As LongPtr, ByVal hdc As LongPtr) As Long
Private Const GWL_STYLE As Long = -16
Private Const WS_CAPTION As Long = &HC00000
Private Const LOGPIXELSX As Long = 88
' --- Deine Einstellungen ---
Private Const SCHRITT As Double = 0.1
Private Const ZELLE_WERT As String = "F41"
Private Const ZELLE_OPTIK As String = "F40"
Private Const BLATT As String = "Blad1"
Private Sub UserForm_Initialize()
' Wert laden
Dim v As Variant
v = ThisWorkbook.Worksheets(BLATT).Range(ZELLE_WERT).Value
If IsNumeric(v) Then
On Error Resume Next
ScrollBar1.Value = CDbl(v) / SCHRITT
On Error GoTo 0
End If
End Sub
Private Sub UserForm_Activate()
Dim hWnd As LongPtr, hdc As LongPtr
Dim r As Range
Dim ScreenPPI As Long
Dim PointsToPixel As Double
Dim pLeft As Long, pTop As Long, pWidth As Long, pHeight As Long
Set r = ThisWorkbook.Worksheets(BLATT).Range(ZELLE_OPTIK)
hWnd = FindWindow("ThunderDFrame", Me.Caption)
' 1. Titelleiste entfernen
SetWindowLong hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) And Not WS_CAPTION
DrawMenuBar hWnd
' 2. Monitor-Skalierung erkennen
hdc = GetDC(0)
ScreenPPI = GetDeviceCaps(hdc, LOGPIXELSX)
ReleaseDC 0, hdc
PointsToPixel = ScreenPPI / 72
' 3. Position berechnen
' Wir nutzen PointsToScreenPixels und addieren einen kleinen Versatz,
' der bei fast allen Windows-Systemen durch den fehlenden Rahmen entsteht.
pLeft = ActiveWindow.PointsToScreenPixelsX(r.Left)
pTop = ActiveWindow.PointsToScreenPixelsY(r.Top)
' Die Größe muss bei 125%/150% Skalierung oft leicht korrigiert werden
' damit sie nicht zu klein wirkt:
pWidth = (r.Width * PointsToPixel)
pHeight = (r.Height * PointsToPixel)
' 4. Windows-Befehl: Position setzen
' Falls es immer noch minimal verschoben ist,
' ändere hier pLeft + 1 oder pTop + 1
SetWindowPos hWnd, 0, pLeft, pTop, pWidth, pHeight, &H40
' 5. ScrollBar anpassen
With ScrollBar1
.Move 0, 0, Me.InsideWidth, Me.InsideHeight
.Min = 0
.Max = 1000
End With
End Sub
' --- Steuerung ---
Private Sub ScrollBar1_Scroll(): Update: End Sub
Private Sub ScrollBar1_Change(): Update: End Sub
Private Sub Update()
On Error Resume Next
ThisWorkbook.Worksheets(BLATT).Range(ZELLE_WERT).Value = ScrollBar1.Value * SCHRITT
On Error GoTo 0
End Sub
Frage kann mir bitte jemand helfen bei diesem problem
wäre super wenn mir jemand helfen könnte


