vba - 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
该代码旨在将单元格中的电子邮件作为公式,并在单击命令按钮时将它们作为地址输出到密件抄送框中。
当我单击按钮时,此功能适用于 Excel 2016,但当我使用 Excel 2010 将文件转发给同事时不起作用,而是收到错误
运行时错误“13”:类型不匹配
突出显示文本行 'If cell.Value Like "? @? .?*" Then'
任何人都可以帮助我吗?
谢谢
解决方案
我刚刚解决了与该错误类似的问题。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
推荐阅读
- c++ - 为什么 std::ostreambuf_iterator 截断整数?
- angular - 无法接收带有 Angular 8 注入的 http 类的 XML 响应
- angular - 在使用 socket.io 的 Angular 应用程序中处理反向代理
- python - 通过回调而不是轮询更新长进程的进度
- javascript - 将数据传递给自定义选择器
- c# - 如何在c#中的数组列表中打印数组的单个单元格
- perl - 如何转换 Perl 以使用 XML/XSLT/XSL-FO 创建 PDF 文件
- csv - 如何使用 apache nifi 从值中删除特定文本
- node.js - 如何将 discord.js 机器人部署到 Cloud Functions?
- kubernetes-helm - 在 HELM values.yaml 中引用之前声明的值