+ Reply to Thread
Results 1 to 2 of 2

Macro for Email attachments from excel list fails when first line is " "

  1. #1
    Registered User
    Join Date
    05-13-2019
    Location
    Mooresville, NC
    MS-Off Ver
    O365
    Posts
    1

    Macro for Email attachments from excel list fails when first line is " "

    I have this macro that is supposed to send an email with an attachment based on a list in excel. The excel file is populating based on if/then to match certain criteria. So the problem is if the first line results in a " " no emails are sent. Anybody have any solutions? The macro is below with an outline of the data it pulls from

    Doc2.docx


    Sub Send_email_fromexcel()
    Dim edress As String
    Dim subj As String
    Dim message As String
    Dim outlookapp As Object
    Dim Outlookmailitem As Object
    Dim myAttachments As Object
    Dim path As String
    Dim lastrow As Integer
    Dim attachment As String
    Dim x As Integer
    x = 1


    Do While Sheet4.Cells(x, 1) <> ""
    'fOR X=1 To 10
    Set outlookapp = CreateObject("Outlook.application")
    Set Outlookmailitem = outlookapp.createitem(0)
    Set myAttachments = Outlookmailitem.Attachments
    path = "G:\"
    edress = Sheet4.Cells(x, 5)
    subj = "bills"
    Filename = Sheet4.Cells(x, 8)
    attachment = path + Filename
    Outlookmailitem.To = edress
    Outlookmailitem.cc = ""
    Outlookmailitem.bcc = ""
    Outlookmailitem.subject = subj
    Outlookmailitem.body = "Kim, Bills for locations you are attached. Thanks!"

    myAttachments.Add (path + Filename)
    Outlookmailitem.display
    Outlookmailitem.send

    lastrow = lastrow + 1
    edress = ""
    x = x + 1
    On Error Resume Next

    Loop
    Set outlookapp = Nothing
    Set Outlookmailitem = Nothing
    End Sub
    Last edited by jgriffi; 05-13-2019 at 03:44 PM.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Macro for Email attachments from excel list fails when first line is " "

    I assume you mean the cell is "" instead of " " as I would think a " " would work.

    Change x=1 to:
    Please Login or Register  to view this content.
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

+ 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. [SOLVED] "ActiveWorkbook.Path" fails - triggers "Compile Error Object required"
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-15-2018, 02:58 PM
  2. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  3. [SOLVED] Why does the "CountIF" function fails on value "Monday Week 1"?
    By kashbg in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-02-2015, 03:24 PM
  4. How to change "From" & to have a dynamic "Subject" line in Excel Mailing
    By andy_iyeng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2012, 03:04 AM
  5. Email Attachments to "To:" and not to "CC:"
    By ran1 in forum Outlook Formatting & Functions
    Replies: 4
    Last Post: 09-24-2010, 07:23 AM
  6. [SOLVED] Find method fails in Excel 2003 ("Subscript out of range")
    By Guy Jara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2006, 12:10 AM
  7. [SOLVED] textbox value to be used as a "subject" line within an email
    By excelwatcher in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-07-2006, 12:35 AM

Tags for this Thread

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