0

我有以下代码,在这个之前的 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

当运行 .send '将立即发送使用 .display 手动发送行时,我收到以下错误消息。运行时错误“2147467259 (80004005)”:Outlook 无法识别一个或多个名称

工作表名称提示确实存在,有什么想法吗?

谢谢!

4

1 回答 1

0

只是为了跟进我提到的关于变量声明的内容......当你这样做时:

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

您没有指定类型,Email_Subject, Email_Send_From因此这些被视为类型 Variant。与Mail_Object下一行相同:

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

虽然这些不会导致这个特定错误,但如果变量设置不正确,它们肯定会导致其他错误(例如,Variant 可能包含对象或数组而不是其余代码期望的字符串等)

否则,我将首先清理上面的代码,然后用 替换.Display进行.Send故障排除并确保在电子邮件中正确设置所有内容。

于 2013-04-12T17:58:48.900 回答