+ Reply to Thread
Results 1 to 6 of 6

How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send email

  1. #1
    Registered User
    Join Date
    12-15-2020
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    5

    How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send email

    data sheet.jpg

    I have a excel file that has two sheets.
    Sheet1 has few columns and each column contains dates(reminder dates for documents expiring such as insurance card expiration date, license expiration date etc etc).
    1. I want to be able find all dates that are expiring within next 30 days or less from today.
    2. add them to sheet2
    3. Send sheet2 via gmail to a few recepients using (smtp.gmail.com).

    I have implimented all of this but its getting stuck at two points
    Firstly, it only picksup the first date it encounters that meets the criteria and writes it to sheet2. Thats it. Does not go write next field.
    Secondly it fails to send email via Attachments.add

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send emai

    Post a sample workbook including your current code.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-15-2020
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    5

    Re: How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send emai

    the error its giving is runtime error 13 "type mismatch"
    source_file = "\...\VBA_EmpReminderProgram\" & ThisWorkbook.Worksheets(1).Cells(4, "N").Value

    .Attachments.Add source_file

    also pl see datasheet.jpg in my first post for code and datasheet.

  4. #4
    Registered User
    Join Date
    12-15-2020
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    5

    Re: How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send emai

    Public Sub Send_Reminder_List()
    Dim myMail As CDO.Message
    Set myMail = New CDO.Message
    myMail.Configuration.Fields.Item("/cdo/configuration/smtpusessl") = True
    myMail.Configuration.Fields.Item("/cdo/configuration/smtpauthenticate") = 1
    myMail.Configuration.Fields.Item("/cdo/configuration/smtpserver") = "smtp....."
    myMail.Configuration.Fields.Item("/cdo/configuration/smtpserverport") = 465
    myMail.Configuration.Fields.Item("/cdo/configuration/sendusing") = 2
    myMail.Configuration.Fields.Item("/cdo/configuration/sendusername") = "******"
    myMail.Configuration.Fields.Item("/cdo/configuration/sendpassword") = "****"
    myMail.Configuration.Fields.Update

    'pp EXPIRATION CHECK AND SEND MAIL
    Dim ppCell As Range
    Dim source_file As Variant
    For Each ppCell In Sheet1.Range("D2:D11")
    If ppCell.Value = Date - 1 Then
    Sheet2.Range("A2").Value = Sheet1.Range("A2").Value
    Sheet2.Range("B2").Value = Sheet1.Range("B2").Value
    Sheet2.Range("C2").Value = Sheet1.Range("C2").Value
    Sheet2.Range("D2").Value = Sheet1.Range("D2").Value
    End If
    Next ppCell
    ThisWorkbook.Save
    source_file = "\VBA_EmpReminderProgram\" & ThisWorkbook.Worksheets(1).Cells(4, "N").Value
    'source_file = Worksheets("Sheet1").Cells(3, "N").Value
    With myMail
    .Subject = "pp"
    .From = "*****"
    .To = "***"
    .TextBody = "This is a sample email"
    .Attachments.Add source_file
    'Worksheets("Sheet1").Cells(4, "N").Value
    On Error Resume Next
    End With
    myMail.Send
    Set myMail = Nothing
    '.Close SaveChanges:=True
    End Sub
    Last edited by SSM34; 12-18-2020 at 01:24 AM.

  5. #5
    Registered User
    Join Date
    12-15-2020
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    5

    Re: How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send emai

    added sample.xlsm
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-15-2020
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    5

    Re: How to write values from sheet1 to sheet2 and attach .xlsm File to Gmail and send emai

    Hi
    Could you pl take a look at this?

+ 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] take screenshot and attach to email using gmail
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-07-2020, 04:00 AM
  2. Excel VBA to Attach File And Automatically Send Email
    By leenguyen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2019, 12:21 PM
  3. Code to send email with table on the email body via gmail
    By ivhee00 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2017, 12:24 AM
  4. [SOLVED] Macro to send email via gmail program
    By excelnoob_15 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-13-2016, 06:52 PM
  5. [SOLVED] Button to send an email via Gmail
    By Drayde in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-28-2014, 08:23 AM
  6. Replies: 8
    Last Post: 12-22-2013, 01:16 PM
  7. Write Data from Sheet1 to sheet2 Until
    By cunning in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 09-10-2005, 01:11 AM

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