Thread: [Solved] Run Macro on Cell Lost Focus
View Single Post
 
Old 04-03-2017, 10:47 AM
hockeyman9474 hockeyman9474 is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Apr 2017
Posts: 1
hockeyman9474 is on a distinguished road
Default Run Macro on Cell Lost Focus

I have a word doc im using as form. There are a few cells I am using as currency. I am using the following code (which work) but I can't figure out how to run the macro when loosing focus in a cell on the table in word. Any ideas?

Code:
Sub CurrConvert()
'
' CurrConvert Macro
'
'
 Dim tCell As Word.Cell
    Dim tRange As Range
    If Selection.Type = wdSelectionIP Or Not Selection.Information(wdWithInTable) Then
        MsgBox "Select numerical values in tables cells before running this macro.", , "Error"
        Exit Sub
    End If
    For Each tCell In Selection.Cells
        Set tRange = tCell.Range
        tRange.End = tRange.End - 1
        With tRange
            If IsNumeric(tRange) Then
                .Text = FormatCurrency(Expression:=.Text)
            End If
            On Error GoTo Skip
Skip:
        End With
    Next tCell
End Sub

Last edited by macropod; 04-03-2017 at 04:16 PM. Reason: Added code tags
Reply With Quote