开发者

What is causing an Excel 2007 to skip onerror in a 64bit environment?

I have created a vba program in Excel 2007 on a 32bit XP machine that runs without error. However when I try to run the same spreadsheet on a 64bit Server 2008 R2 Remote desktop services machine, I receive an unrecoverable error. Here is the code that is causing the trouble:

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo ErrHandle

    Dim MachPhone As String
    Dim ConPhone As String

    Select Case Target.Row

    Case 12
        MachPhone = PhoneFormat(Range("B12"))
        Range("B12").Value = MachPhone
    Case 开发者_C百科13
        ConPhone = PhoneFormat(Range("B13"))
        Range("B13").Value = ConPhone
    End Select

    ErrHandle:
        Exit Sub
        Resume

End Sub

The PhoneFormat function checks the format of a phone number and returns a formated phone number or the original string, if it can't figure out what the phone number is.


Disabling events:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim val As String
Dim Phone As String
Dim rw As Long

    On Error GoTo ErrHandle

    rw = Target.Row
    If rw = 12 Or rw = 13 Then
        With Target.Parent.Cells(rw, 2)
            val = Trim(.Value)
            Phone = Phoneformat(val)
            If val <> Phone Then
                Application.EnableEvents = False
                .Value = Phone
                Application.EnableEvents = True
            End If
        End With
    End If
    Exit Sub

ErrHandle:
    Application.EnableEvents = True

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜