简体   繁体   English

Excel 2010 VBA .send 错误

[英]Excel 2010 VBA .send error

I have the following code, which works FINE for 10 macros prior to this one (I use a call x, call Y macro), but this one does not want to work.我有以下代码,它可以在此之前的 10 个宏中正常工作(我使用调用 x,调用 Y 宏),但是这个代码不想工作。

Sub Send_Tips()
Application.DisplayAlerts = False
Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer
Dim Mail_Object, nameList As String, o As Variant
    Email_Send_From = ""
     For i = 1 To 1 'use cells 1 to 1 in column "A" where names are stored
If Sheets("Tips").Range("A1").Value <> "" Then
    nameList = nameList & ";" & Sheets("Tips").Range("A" & i).Value
End If
Next
    Set Mail_Object = CreateObject("Outlook.Application")
    With Mail_Object.CreateItem(o)
        .Subject = "Dealer Action Plans"
        .To = nameList
        .Body = "Please find attached the latest version of the Dealer Action Plans." 
        'Make a copy of the active sheet and save it to
 'a temporary file
 Worksheets("Tips").Activate
ActiveSheet.Copy
Set wb = ActiveWorkbook
Filename = "Tips.pdf"
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

Worksheets("Tips").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="c:\aaaWork\Tips.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

'    ActiveWorkbook.SaveAs Filename:="C:\aaaWork\NC1.PDF", FileFormat:=17

        .Attachments.Add "C:\aaaWork\Tips.PDF"
        .send 'Will send straight away use .display to send manually
       ActiveWorkbook.Close Saved = True
        Kill "C:\aaaWork\Tips.PDF"
End With
    Application.DisplayAlerts = True
End Sub

I get the following error message when the line .send 'Will send straight away use .display to send manually is ran.当 .send 'Will send directly use .display to send 行运行时,我收到以下错误消息。 Run Time Error '2147467259 (80004005)': Outlook doesn't recognise one or more names运行时错误“2147467259 (80004005)”:Outlook 无法识别一个或多个名称

The sheet name Tips does exist, any ideas?工作表名称提示确实存在,有什么想法吗?

Thanks!谢谢!

Just to follow-up on what I mentioned about the variable declarations... when you do this:只是为了跟进我提到的关于变量声明的内容......当你这样做时:

Dim Email_Subject, Email_Send_From, Email_Body As String, i As Integer

you have not specified a TYPE for Email_Subject, Email_Send_From so these are treated as type Variant.您尚未为Email_Subject, Email_Send_From指定 TYPE Email_Subject, Email_Send_From因此将它们视为 Variant 类型。 Same with Mail_Object on the next line:与下一行的Mail_Object相同:

Dim Mail_Object, nameList As String, o As Variant

Rewrite these lines per below, so that your string variables are correctly declared:重写下面的这些行,以便正确声明您的字符串变量:

Dim Email_Subject$, Email_Send_From$, Email_Body$, i As Integer Dim Mail_Object$, nameList As String, o As Variant Dim Email_Subject$, Email_Send_From$, Email_Body$, i As Integer Dim Mail_Object$, nameList As String, o As Variant

Although these did not cause this particular error, they could certainly cause other errors if the variables are set improperly (eg, a Variant might contain an object or an array instead of a string which the rest of the code expects, etc.)虽然这些不会导致这个特定的错误,但如果变量设置不当,它们肯定会导致其他错误(例如,一个 Variant 可能包含一个对象或一个数组,而不是其余代码所期望的字符串等)

Otherwise I would start just by cleaning up the code per above, and then substitute the .Display for the .Send to troubleshoot and make sure everything is set properly in the Email.否则,我将首先清理上面的代码,然后将.Display替换为.Send以进行故障排除并确保电子邮件中的所有设置都正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM