excel 2010上的运行时错误13,但适用于excel 2016


Private Sub CommandButton64_Click() 
Dim cell As Range
Dim strto As String
For Each cell In ThisWorkbook.Sheets("Sheet2").Range("C3:L197")
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next cell
If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
On Error GoTo cleanup
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.BCC = strto
.Subject = "Enter subject here"
.Body = "" ' EMPTY FOR NOW
'USE THIS FOR ENTERING NAMES OF RECIPIENTS IN BODY TEXT "here"
'"Dear" & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Enter body text " & _
"here"
'You can add files also like this
'.Attachments.Add ("C:test.txt")
'.Send 'Or use Display
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

该代码旨在将单元格中的电子邮件作为一个公式,并在单击命令按钮时将其输出为bcc框中的地址。

当我点击按钮时,该功能在Excel 2016上有效,但当我使用Excel 2010将文件转发给同事时,该函数不起作用,相反,我收到错误

运行时错误"13":类型不匹配

突出显示文本行"If cell"。值类似于"?@?.?*"然后'

有人能帮我吗?

感谢

我刚刚处理了一个类似的错误问题。2010年版本的工作表很可能存在计算错误。

如果你不能清除表上的错误,@Vityata建议你使用

Not IsError

因此,对于您的代码,使循环更像:

For Each cell In ThisWorkbook.Sheets("Sheet2").Range("C3:L197")
If Not IsError(cell) Then
If cell.Value Like "?*@?*.?*" Then strto = strto & cell.Value & ";"
End If
Next cell

最新更新