OVH Cloud OVH Cloud

Position d'un UserForm

3 réponses
Avatar
Line
Bonjour ou bonsoir tout le monde

Est-il possible de faire coincider la position d'un UserForm avec
la cellule active???

UserForm.Top = ActiveCell.Top
UserForm.Left = ActiveCell.Left

Ne donne pas les résultats espérés

Un gros merci d'avance

Line

3 réponses

Avatar
Michel Pierron
Bonsoir Line;
Comme ceci:

Option Explicit
Private Declare Function GetDC& Lib _
"user32.dll" (ByVal hwnd&)
Private Declare Function GetDeviceCaps& _
Lib "gdi32" (ByVal hDC&, ByVal nIndex&)

Sub UserFormAlign()
' 1 inch = 72 points for usually 96 or 120 dpi
Dim x#, y#, w#, h#
x = GetDeviceCaps(GetDC(0), 88) / 72
y = GetDeviceCaps(GetDC(0), 90) / 72
With UserForm1
.StartUpPosition = 0
.Left = ActiveWindow.PointsToScreenPixelsX(ActiveCell.Left * x) * 1 / x
.Top = ActiveWindow.PointsToScreenPixelsY(ActiveCell.Top * y) * 1 / y
.Show
End With
End Sub

MP

"Line" a écrit dans le message de news:

Bonjour ou bonsoir tout le monde

Est-il possible de faire coincider la position d'un UserForm avec
la cellule active???

UserForm.Top = ActiveCell.Top
UserForm.Left = ActiveCell.Left

Ne donne pas les résultats espérés

Un gros merci d'avance

Line


Avatar
Line
Merci beaucoup Michel!!! Et Merci aussi pour le UserForm
transparent trouvé chez Misange. Très pratique.

Bonne fin de soirée...


"Michel Pierron" wrote:

Bonsoir Line;
Comme ceci:

Option Explicit
Private Declare Function GetDC& Lib _
"user32.dll" (ByVal hwnd&)
Private Declare Function GetDeviceCaps& _
Lib "gdi32" (ByVal hDC&, ByVal nIndex&)

Sub UserFormAlign()
' 1 inch = 72 points for usually 96 or 120 dpi
Dim x#, y#, w#, h#
x = GetDeviceCaps(GetDC(0), 88) / 72
y = GetDeviceCaps(GetDC(0), 90) / 72
With UserForm1
..StartUpPosition = 0
..Left = ActiveWindow.PointsToScreenPixelsX(ActiveCell.Left * x) * 1 / x
..Top = ActiveWindow.PointsToScreenPixelsY(ActiveCell.Top * y) * 1 / y
..Show
End With
End Sub

MP

"Line" a écrit dans le message de news:

Bonjour ou bonsoir tout le monde

Est-il possible de faire coincider la position d'un UserForm avec
la cellule active???

UserForm.Top = ActiveCell.Top
UserForm.Left = ActiveCell.Left

Ne donne pas les résultats espérés

Un gros merci d'avance

Line







Avatar
seagull62
Line a écrit le 04/04/2006 à 01h18 :
Merci beaucoup Michel!!! Et Merci aussi pour le UserForm
transparent trouvé chez Misange. Très pratique.

Bonne fin de soirée...


"Michel Pierron" wrote:

Bonsoir Line;
Comme ceci:

Option Explicit
Private Declare Function GetDC& Lib _
"user32.dll" (ByVal hwnd&)
Private Declare Function GetDeviceCaps& _
Lib "gdi32" (ByVal hDC&, ByVal nIndex&)

Sub UserFormAlign()
' 1 inch = 72 points for usually 96 or 120 dpi
Dim x#, y#, w#, h#
x = GetDeviceCaps(GetDC(0), 88) / 72
y = GetDeviceCaps(GetDC(0), 90) / 72
With UserForm1
..StartUpPosition = 0
..Left = ActiveWindow.PointsToScreenPixelsX(ActiveCell.Left * x) * 1 / x
..Top = ActiveWindow.PointsToScreenPixelsY(ActiveCell.Top * y) * 1 / y
..Show
End With
End Sub

MP

"Line" a écrit dans le
message de news:

Bonjour ou bonsoir tout le monde

Est-il possible de faire coincider la position d'un UserForm avec
la cellule active???

UserForm.Top = ActiveCell.Top
UserForm.Left = ActiveCell.Left

Ne donne pas les résultats espérés

Un gros merci d'avance

Line










Bonjour,
j'ai ceci dans une feuile, comment puis-je appliquer le code donné plus haut pour que sur le clic droit mon userform s'ouvre à proximité de la cellule active?

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

UserForm1.Show

Cancel = True

End Sub