直接VBA将电子表格的副本保存在outlook中的指定文件夹中

时间:2013-01-14 15:44:13

标签: excel vba excel-vba outlook outlook-vba

我有代码可以获取选择工作表的副本,但是很难指导outlook中的草稿文件夹将草稿电子邮件发送到。我要将草稿电子邮件发送到的文件夹的名称是“Draft NDIC”。这是代码:

Sub Mail_Body_NDIC()
  Dim rng As Range
  Dim OutApp As Object
  Dim OutMail As Object
  With Application
      .EnableEvents = False
      .ScreenUpdating = False
  End With

  Set rng = Nothing
  Set rng = Sheets("NDIC Renewals").UsedRange
  'You can also use a sheet name
  'Set rng = Sheets("YourSheet").UsedRange

  Set OutApp = CreateObject("Outlook.Application")
  Set OutMail = OutApp.CreateItem(0)

  On Error Resume Next
  With OutMail
      .To = "dvandervieren@enerplus.com"
      .CC = ""
      .BCC = ""
      .Subject = "NDIC Renewals for the Next 90 Days"
      .Body = ""
      .HTMLBody = RangetoHTML(rng)
      .Save   'or use .Display
  End With
  On Error GoTo 0

  With Application
      .EnableEvents = True
      .ScreenUpdating = True
  End With

  Set OutMail = Nothing
  Set OutApp = Nothing
 End Sub

1 个答案:

答案 0 :(得分:0)

"您需要使用.Move方法,并将olDestFolder作为参数。" David Van der Vieren

http://blog.saieva.com/2010/03/27/move-messages-to-folders-with-outlook-vba/