Option Explicit
Function GetDiagonalPositionLeft(SHAP, SHAP2) As Double
'*****************************************
'Reposition in terms of left a shape(1) at the intersection of another shape(2) of type "MsoLine" according to the top of the shapes(1)
'Version coded by patricktoulon
'Version1 1.0
'Date version:08/04/2024
'Request from @Dudu2 in a discussion on ExcelDownloads
'https://excel-downloads.com/threads/vba-determiner-la-pente-de-la-forme-ligne-ou-fleche-ou-mieux-son-equation.20082379/page-2#posts
'*****************************************
Dim Lg#, HT#, Tp#, NewTp#, NewLg#, NewHt, Bottom#, DiffWidth, L1#, L2, LF#
'Position data and size of the shapes (SHAP2 = "LINE")
Lg = SHAP.Width 'Width of shape (MsoLine)
HT = SHAP.Height 'Height of shape (MsoLine)
Tp = SHAP.Top 'Top of shape (MsoLine)
Bottom = SHAP.Top + SHAP.Height 'Bottom of shape (MsoLine)
NewTp = SHAP2.Top 'Width of shape(Msoline or MsoArrow
NewHt = Bottom - NewTp 'Height of intersection rectangle
NewLg = Lg / (HT / NewHt) 'Reducing the width of the rectangle to the same ratio as reducing its height
DiffWidth = Abs(Lg - NewLg) 'Difference in width of the two occupation rectangles
'Two possibilities of left according to the vertical and horizontal flip rotation
L1 = SHAP.Left + NewLg - (SHAP2.Width / 2)
L2 = SHAP.Left + DiffWidth - (SHAP2.Width / 2)
'Selection of one of the two possibilities depending on the flip
If SHAP.VerticalFlip Then
If SHAP.HorizontalFlip Then LF = L2 Else LF = L1
Else
If SHAP.HorizontalFlip Then LF = L1 Else LF = L2
End If
GetDiagonalPositionLeft = LF
End Function
Sub applique() 'SUB DE TEST
Dim X#
With ActiveSheet
X = GetDiagonalPositionLeft(.Shapes("ligne"), .Shapes("rectrouge"))
.Shapes("rectrouge").Left = X
End With
End Sub