ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 2658|回复: 1

[求助] 如何用VBA使每次转发时只转发附件而将正文清空

[复制链接]

TA的精华主题

TA的得分主题

发表于 2009-3-3 10:47 | 显示全部楼层 |阅读模式
如题,对于outlook vba不了解,不知这个应该怎么实现。

TA的精华主题

TA的得分主题

发表于 2009-3-4 22:45 | 显示全部楼层
请参考这个帖子:
http://www.codeforexcelandoutloo ... -send-clean-emails/

我把代码拷贝出来,我试过了,是可以的.

   Sub SaveFilesAndSendCleanEmail()
' save attachments to desktop folder (create one if necessary),
' then email them out one by one

    Dim Msg As Outlook.MailItem
    Dim NewMsg As Outlook.MailItem
    Dim MsgColl As Object
    Dim MsgAttach As Outlook.Attachments
    Dim NewMsgAttach As Outlook.Attachments
    Dim ThisAttach As Outlook.Attachment
    Dim i As Long
    Dim strMyDesktop As String
    Dim strDestinationFolder As String
    Dim strFileN As String
    Dim fso As Object
    Dim item As Object
  
   On Error Resume Next
   Set MsgColl = ActiveExplorer.Selection
   On Error GoTo 0
  
   If MsgColl Is Nothing Then
     MsgBox "Nothing selected"
     GoTo ExitProc
   End If
  
   ' get path of user's desktop and build a string for the destination folder
   strMyDesktop = MyDesktopPath & "\"
   strDestinationFolder = strMyDesktop & "Saved Attachments\"
  
   ' get a FileSystemObject reference
   Set fso = GetFSO
  
   ' check if the folder exists, if not then create it to store the attachments
   If fso.FolderExists(strDestinationFolder) = False Then
       MkDir strDestinationFolder
   End If
  
   ' loop through each selected item and make sure they are all mailitems
   ' if so, then save each attachment from each message to the destination folder
   For Each item In MsgColl
     If item.Class = olMail Then ' it's an email, not a post, note, meeting request, etc
       Set Msg = item
       Set MsgAttach = Msg.Attachments
  
       If MsgAttach.count > 0 Then
         For i = 1 To MsgAttach.count
           MsgAttach.item(i).SaveAsFile strDestinationFolder & MsgAttach.item(i).FileName
         Next i
       End If
     End If
   Next item
  
   ' Forward attachments to another email address
   ' first create the email, then loop through destination folder, adding attachments to the email and deleting them from the folder as we go
   Set NewMsg = CreateItem(olMailItem)
   Set NewMsgAttach = NewMsg.Attachments
  
   strFileN = Dir(strDestinationFolder & "*.*")
  
   Do While Len(strFileN) > 0
     NewMsgAttach.Add strDestinationFolder & strFileN
     Kill strDestinationFolder & strFileN
     strFileN = Dir
   Loop
  
   NewMsg.Display
  
   ' clean up emails (optional)
   If MsgBox("Would you like to delete the selected emails now?", vbInformation + vbYesNo) = vbYes Then
     For i = 1 To MsgColl.count
       Set Msg = MsgColl.item(i)
       With Msg
         .UnRead = False
         .Delete
       End With
     Next i
   End If
  
   If MsgBox("Delete destination folder that was created on your desktop?", vbInformation + vbYesNo) = vbYes Then
     RmDir strDestinationFolder
   End If
  
ExitProc:
   Set Msg = Nothing
   Set MsgColl = Nothing
   Set MsgAttach = Nothing
   Set fso = Nothing
   Set NewMsg = Nothing
   Set NewMsgAttach = Nothing
   End Sub


Function MyDesktopPath() As String
' returns path to Desktop folder as a String
' from http://tinyurl.com/GetFolderPath
Dim WSHShell As Object

Set WSHShell = CreateObject("WScript.Shell")
MyDesktopPath = WSHShell.SpecialFolders("Desktop")

Set WSHShell = Nothing
End Function

Function GetFSO() As Object
' returns a reference to the Scripting.FileSystemObject to the calling sub
On Error Resume Next
   Set GetFSO = GetObject(, "Scripting.FileSystemObject")
On Error GoTo 0

If GetFSO Is Nothing Then
   Set GetFSO = CreateObject("Scripting.FileSystemObject")
End If
End Function
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-20 09:29 , Processed in 0.035271 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表