title: VBA Excel Email Automation every 30 min
body: <p>I want an excel file to save (stamp time) every thirty minutes and email itself to me. I have gotten the file to save and send it to me.  However, when I try to do this continuously for 30 min, I run into issues. below is my code, anyone have any ideas? I tried doing a loop function, so while A1 = 0 it will keep running, but when I click stop button, it will change A1 = 1, and basically stop. I also want to be able to run this program and still be able to use excel  and not be disturbed, any ideas?</p>
  
  <pre><code>Option Explicit
  
  Private Sub CommandButton1_Click()
  Range("A1").Value = 0
  Do While Range("A1").Value = 0
  Loop
  
  ActiveWorkbook.SaveAs "VBA Email " &amp; Format(Date, "mm-dd-yyyy") &amp; " " &amp; Format(Time, "h.mm AM/PM") &amp; ".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
  </code></pre>