Advertisement
small-bao

vba

Jul 14th, 2024 (edited)
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub 发送邮件()
  2. '保存当前excel
  3. ThisWorkbook.Save
  4.  
  5. '让excel沟通outlook 要将工具/引用中的Microseft Outlook *.0 Object Library(其中*为你Microseft Outlook的版本号)选上
  6. Dim 信差 As Outlook.Application
  7. Set 信差 = New Outlook.Application
  8. '创建邮件实例
  9. Dim 新邮件 As MailItem
  10. Set 新邮件 = 信差.CreateItem(olMailItem)
  11. Dim filePath As String
  12.     filePath = ThisWorkbook.FullName
  13.     'MsgBox filePath
  14.    
  15.     With 新邮件
  16.         '设置收件人地址
  17.        .To = "small-bao@foxmail.com"
  18.         '设置抄送收件人地址
  19.        .CC = ""
  20.         '设置邮件主题
  21.        .Subject = Date & "  K/B复判报表"
  22.         '设置邮件内容
  23.        .Body = Date & "  K/B复判报表"
  24.         '设置附件
  25.        .Attachments.Add (filePath)
  26.         '显示UI
  27.        .Display
  28.         '发送邮件
  29.        '.Send
  30.  
  31.     End With
  32.    
  33.     ' 清理
  34.    Set 新邮件 = Nothing
  35.     Set 信差 = Nothing
  36.    
  37. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement