将选定文件夹中的文件附加到 Outlook 电子邮件

Attach files from a selected folder to an Outlook email

我需要创建一封 Outlook 电子邮件并从一个文件夹中附加最多 10 个文件。
如果有 16 个文件,则应创建 2 个电子邮件,第一个包含 10 个文件,第二个包含剩余的 6 个文件。

当我尝试在我的循环中附加文件时,它给出了这个错误

Object doesn't support this property or method. I have no idea what to do. Could anyone please have a look?

这是代码。当您 运行 代码时,您可以 select 任何包含文件的文件夹。

Sub attach()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    'Dim temp_Attach As Object
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Show
        .Title = "Select a Folder"
        sFolder = .SelectedItems(1)
    End With
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(sFolder)
    Set fls = f.Files
    
    
    Z = 10
    
    For d = 0 To fls.Count - 1 Step 10
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        'On Error Resume Next
        With OutMail
            .To = "abc@gmail.com"
            .CC = ""
            .subject = "file"
            
            y = 0
            For Each x In fls
                If y < Z Then
                    .Attachements.Add (sFolder & "\" & x.Name)
                    y = y + 1
                Else
                    Exit For
                End If
            
                Z = Z + 10
            
            Next
            .Display
            
        End With
    
    Next
    
End Sub

您拼错了单词 Attachments(您将其作为 Attachements)。

下面的代码对我来说就像一个魅力:

Set OutMail = OutApp.CreateItem(0)
    
With OutMail
      .To = "abc@gmail.com"
      .CC = ""
      .subject = "file"
        
      y = 0
     
      For Each x In fls
        If y < Z Then
           .Attachments.Add (sFolder & "\" & x.Name)
           y = y + 1
        Else
           Exit For
        End If
        
        Z = Z + 10
        
     Next
     .Display
        
  End With

Next