【发布时间】:2014-10-10 05:54:46
【问题描述】:
我想要一个 excel 文件每三十分钟保存一次(盖章时间),然后通过电子邮件发送给我。我已将文件保存并发送给我。但是,当我尝试连续执行此操作 30 分钟时,我遇到了问题。下面是我的代码,有人有什么想法吗?我尝试做一个循环功能,所以当A1 = 0时它会继续运行,但是当我点击停止按钮时,它会改变A1 = 1,并且基本上停止。我也希望能够运行这个程序并且仍然能够使用excel并且不受干扰,有什么想法吗?
Option Explicit
Private Sub CommandButton1_Click()
Range("A1").Value = 0
Do While Range("A1").Value = 0
Loop
ActiveWorkbook.SaveAs "VBA Email " & Format(Date, "mm-dd-yyyy") & " " & Format(Time, "h.mm AM/PM") & ".xlsm"
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "xxxx@gmail.com"
.Subject = "VBA Email"
.Attachments.Add (ActiveWorkbook.FullName)
.Display
Application.SendKeys "%s"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Application.Wait (Now + TimeValue("0:00:02"))
End Sub
Private Sub CommandButton2_Click()
Range("A1").Value = 1
End Sub
【问题讨论】:
-
您遇到了什么问题?它在做什么不是你期望它做的?编辑您的问题以添加信息。
标签: vba email automation recurring