我一直在询问比我更熟悉 VBA 的人,但没有我希望的那种运气。这是我需要的:
- 主题行中带有“Stats1”、“Stats2”、“Stats3”(等)的传入电子邮件
- 规则被触发,捕获发件人的电子邮件地址
- 打开工作簿并将电子邮件地址传递给工作簿(例如:emaillog.xlsm)
- 附加到工作簿(不覆盖)
- 在“emaillog.xlsm”上记录电子邮件地址、时间和日期
- 运行一个 excel 脚本(例如 emailsend.xlsm)
- 将数据范围从“emailsend.xlsm”发送到“emaillog.xlsm”上的最新条目
- 保存并关闭“emaillog.xlsm”
这是我要发送的 Excel 部分的内容:
Public dTime As Date
Sub AutoSchedule1()
dTime = Now() + TimeValue("01:00:00")
Sheet("Sheet1").Range("u1").Value = "Email On, next send at " & Hour(dTime) & ":" & Minute(dTime)
ActiveWorkbook.RefreshAll
Application.OnTime dTime, "SendStatsTeam"
If Hour(dTime) >= 18 Then
Application.OnTime dTime, "SendStatsTeam", , False
Exit Sub
End If
End Sub
Sub SendStatsTeam()
Dim AWorksheet As Worksheet
Dim Sendrng As Range
Dim rng As Range
Dim Hournow As Long
AutoSchedule1
On Error GoTo StopMacro
If Hour(Now()) > 12 Then
Hournow = Hour(Now()) - 12
Else
Hournow = Hour(Now())
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sendrng = Worksheets("Sheet1").Range("A1:Z26")
Set AWorksheet = ActiveSheet
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
.Introduction = "Here are your stats"
With .Item
.To = SenderEmailAddress
.CC = ""
.BCC = ""
.Subject = "Stats so far today" & Hour(Now()) & ":" & Application.WorksheetFunction.Text(Minute(Now()), "00")
.Send
End With
End With
rng.Select
End With
AWorksheet.Select
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
End Sub
Sub emailoff()
Application.OnTime dTime, "SendStatsTeam", , False
Worksheets("Sheet2").Range("u1").Value = "Email Off"
End Sub
我意识到我在这里没有正确完成所有事情,因为我对 VBA 还很陌生,但是我已经尽我所能来弄清楚 Outlook 部分。
任何帮助将不胜感激 - 我不介意阅读我只是在我无法弄清楚下一部分该做什么/去哪里的时候。
如果您选择提供帮助,我想添加根据电子邮件主题发送不同范围的不同工作表的功能。
谢谢