簡體   English   中英

Excel 2010出現運行時錯誤13但Excel 2016起作用

[英]Run-time error 13 on excel 2010 but works on 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':類型不匹配

突出顯示文本行“如果cell.Value像‘?@?*?’然后”

有人可以協助我嗎?

謝謝

我只是解決了與此錯誤類似的問題。 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM