+ Reply to Thread
Results 1 to 2 of 2

VBA Run Time Error The Item Has been moved or deleted

Hybrid View

  1. #1
    Registered User
    Join Date
    07-27-2017
    Location
    london england
    MS-Off Ver
    2013
    Posts
    1

    Post VBA Run Time Error The Item Has been moved or deleted

    Can anyone help me please i am trying to send email using excel based on cell dates but after sending email to 1 email address it gives error "Run Time Error Item Has been moved or deleted" And when i reopen the file it sends email to same id that already has been sent the code i am using is below





    Private Sub Workbook_Open()

    Dim i As Long
    Dim OutApp, OutMail As Object
    Dim strto, strcc, strbcc, strsub, strbody As String

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


    For i = 3 To Range("J65536").End(xlUp).Row
    If Cells(i, 13) <> "Y" Then
    If Cells(i, 8) - 7 < Date Then

    strto = Cells(i, 10).Value 'email address
    strsub = "RA " & Cells(i, 6).Value & " is due on Due date " & Cells(i, 7).Value 'email subject
    strbody = "Dear " & Cells(i, 14).Value & vbNewLine & "please update your project status" 'email body

    With OutMail
    .To = strto
    .Subject = strsub
    .Body = strbody
    .Send

    End With

    Cells(i, 11) = "EMail Sent " & Now()
    Cells(i, 12) = "Y"

    End If

    End If
    Next

    Set OutMail = Nothing
    Set OutApp = Nothing
    ActiveWorkbook.Save


    End Sub

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: VBA Run Time Error The Item Has been moved or deleted

    Try slight modification (not tested):

    Private Sub Workbook_Open()
    
    Dim i As Long
    Dim OutApp, OutMail As Object
    Dim strto, strcc, strbcc, strsub, strbody As String
    
    Set OutApp = CreateObject("Outlook.Application")
    
    
    For i = 3 To Range("J65536").End(xlUp).Row
      If Cells(i, 13) <> "Y" Then
        If Cells(i, 8) - 7 < Date Then
          Set OutMail = OutApp.CreateItem(0)
          strto = Cells(i, 10).Value 'email address
          strsub = "RA " & Cells(i, 6).Value & " is due on Due date " & Cells(i, 7).Value 'email subject
          strbody = "Dear " & Cells(i, 14).Value & vbNewLine & "please update your project status" 'email body
          With OutMail
            .To = strto
            .Subject = strsub
            .Body = strbody
            .Send
          End With
          Set OutMail = Nothing
          Cells(i, 11) = "EMail Sent " & Now()
          Cells(i, 13) = "Y"
        End If
      End If
    Next
    
    Set OutApp = Nothing
    ActiveWorkbook.Save
    End Sub
    and please edit your original post to comply with our "code tags rule" - see:

    -----------

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Best Regards,

    Kaper

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 'item has been moved or deleted' Error
    By Aphis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2016, 01:48 PM
  2. Replies: 2
    Last Post: 06-14-2014, 10:46 PM
  3. Replies: 3
    Last Post: 06-03-2014, 12:29 AM
  4. Code to detect if sheets have been moved or deleted
    By Newbie_Nick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2010, 03:29 AM
  5. [SOLVED] Worksheets moved or deleted by unknown means!
    By Dan in forum Excel General
    Replies: 1
    Last Post: 12-05-2005, 06:00 PM
  6. Replies: 2
    Last Post: 01-06-2005, 11:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1