Private Declare Function PathCompactPath Lib "shlwapi" _
Alias "PathCompactPathA" ( _
ByVal hDC As Long, _
ByVal lpszPath As String, _
ByVal dx As Long) As Long
Private Sub TestCell()
Dim myText As String
Dim myShort As String
Dim oLen As Integer
Dim aLen As Integer
myText = Application.Cells(1, 1).Text
UserForm1.Label1.Width = Application.Cells(1, 1).Width
UserForm1.Label1.Caption = myText
oLen = Len(myText)
myShort = TextFun(Me, myText, UserForm1.Label1)
aLen = InStr(1, myShort, Chr(0))
If aLen < oLen And aLen <> 0 Then
Application.Cells(2, 1).Value = myShort
UserForm1.Caption = myShort
Else
Application.Cells(2, 1).Value = myText
UserForm1.Caption = myText
End If
End Sub
Public Function TextFun(oForm As Object, _
ByVal sPath As String, _
oControl As Object) As String
nWidth = oControl.Width
PathCompactPath UserForm1.Label1.[_GethWnd], sPath, nWidth
TextFun = sPath
End Function
Private Sub CommandButton1_Click()
TestCell
End Sub