Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetTimer Lib "user32" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, ByVal uElapse As LongPtr, ByVal lpTimerFunc As LongPtr) As Long
Private Declare PtrSafe Function KillTimer Lib "user32" (ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
#Else
Private Declare Function SetTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
#End If
Private WrapAutoCellCaller As Range, WrapAutoCellValue As Range, WTACC_TimerID&
Private Sub WraptextAutoCallback()
On Error Resume Next
KillTimer 0&, WTACC_TimerID: WTACC_TimerID = 0
Application.ScreenUpdating = False
WrapAutoCellCaller.WrapText = False
WrapAutoCellCaller.WrapText = True
If Not WrapAutoCellValue Is Nothing Then
WrapAutoCellValue.WrapText = False
WrapAutoCellValue.WrapText = True
Set WrapAutoCellValue = Nothing
End If
Application.ScreenUpdating = True
Set WrapAutoCellCaller = Nothing
End Sub
Function WrapAuto(ByVal CellValue As Range, Optional WrapCellValue As Boolean = False) As Variant
WrapAuto = CellValue(1, 1).Value2
Set WrapAutoCellCaller = Application.Caller
If WrapCellValue Then Set WrapAutoCellValue = CellValue(1, 1)
If CellValue(1, 1).HasFormula Then Application.Volatile
If WTACC_TimerID <> 0 Then KillTimer 0&, WTACC_TimerID
WTACC_TimerID = SetTimer(0&, 0&, 1, AddressOf WraptextAutoCallback)
End Function