+ Reply to Thread
Results 1 to 8 of 8

Email automatisation including data from an excel file

  1. #1
    Registered User
    Join Date
    05-19-2021
    Location
    England
    MS-Off Ver
    365
    Posts
    7

    Email automatisation including data from an excel file

    Hello good Afternoon,

    I am trying to automate data collection by including some scripts in my excel spreadsheet. The idea is that every time anybody uses the excel sheet I will receive the data on my email account for verification purposes. Since the excel knowledge of my peers is very limited, I automated everything: they just need to click on a button, select the data file and they automatically will have access to the graphs that they require. At this point, everything runs ok on my script and I'm receiving the emails but I'm really struggling to find a way to include the data as an attachment. On top of that, it is working with xcls files, but I still cannot import any csv data.

    I found several tutorials working with Outlook, but I would prefer to work with Gmail and everything I tried was unfruitful.

    The script that I have right now is:

    Sub Get_Data_From_File()
    Dim filetoopen As Variant
    Dim openbook As Workbook
    Application.ScreenUpdating = False
    filetoopen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xlsx*),*csv*")
    If filetoopen <> False Then
    Set openbook = Application.Workbooks.Open(filetoopen)
    openbook.Sheets(1).Range("A1:P30000").Copy
    ThisWorkbook.Worksheets("Raw Data").Range("A1").PasteSpecial xlPasteValues
    openbook.Close False

    End If
    Application.ScreenUpdating = True


    Dim NewMail As CDO.Message
    Dim mailConfiguration As CDO.Configuration
    Dim fields As Variant
    Dim msConfigURL As String



    Set NewMail = New CDO.Message
    Set mailConfiguration = New CDO.Configuration
    Set fields = mailConfiguration.fields

    With NewMail
    .Subject = "data file"
    .From = "XXXXXXXXX"
    .To = "XXXXXXXXXX"
    .Subject = "Test"
    .TextBody = "en pruebas"


    End With



    msConfigURL = "xxxxxxx"

    With fields
    .Item(msConfigURL & "/smtpusessl") = True
    .Item(msConfigURL & "/smtpauthenticate") = 1

    .Item(msConfigURL & "/smtpserver") = "XXXXXX"
    .Item(msConfigURL & "/smtpserverport") = 465
    .Item(msConfigURL & "/sendusing") = 2
    .Item(msConfigURL & "/sendusername") = "XXXXXXX"

    .Item(msConfigURL & "/sendpassword") = "XXXXXXXX"

    .Update

    End With

    NewMail.Configuration = mailConfiguration
    NewMail.Send

    MsgBox "Data successfully processed", vbInformation



    End Sub


    Please I would appreciate if you can help me to include the relevant script, so the data that is copied at the beginning of the macro is also attached to the automated email. I reckon that my knowledge is extremely limited, in deed, this is the first time I work with macros or VBA.


    Thank you very much in advance for your help,

    Best regards

    Fernando
    Last edited by AliGW; 06-21-2021 at 07:52 AM. Reason: Thread tagged as solved - no need to edit the thread title!

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: email automatisation including data from an excel file

    Not sure if this is what you were trying to accomplish...
    Please Login or Register  to view this content.
    The code uses MS Outlook, copies the data from the selected file (either Excel or CSV) into the email, and also attaches the selected file.

  3. #3
    Registered User
    Join Date
    05-19-2021
    Location
    England
    MS-Off Ver
    365
    Posts
    7

    Re: email automatisation including data from an excel file

    Hello Dangelor,

    Really appreciate your help. Now I can also import csv files, which is really good, thank you!!

    However, I'm still having problems attaching the current excel file in the gmail. I already can send an automatic email, but still struggling trying to attach the current excel file.

    I've been trying to use the .AddAttachment, but it seems that I'm missing something....

    Thanks in advance for your attention,

    Best regards

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: email automatisation including data from an excel file

    Sorry, don't know any gmail code

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: email automatisation including data from an excel file

    Quote Originally Posted by Fertxo View Post

    I've been trying to use the .AddAttachment, but it seems that I'm missing something....
    I would assume the syntax would be...

    Please Login or Register  to view this content.

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: email automatisation including data from an excel file

    Did some searching on Google...

    Possibly...
    Please Login or Register  to view this content.
    Last edited by dangelor; 06-17-2021 at 07:13 AM. Reason: corrected server typo

  7. #7
    Registered User
    Join Date
    05-19-2021
    Location
    England
    MS-Off Ver
    365
    Posts
    7

    Re: email automatisation including data from an excel file

    Yes it is!!!

    Really appreciate your help!!

    Thanks for helping me moving forward!!

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: SOLVED-Email automatisation including data from an excel file

    Glad to help. Learned something myself!

+ 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] VBA to send email using data from the EXCEL including email address, subject and body text
    By ec4excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2016, 11:07 AM
  2. Creating Email & Including Specific Corresponding Data from Range
    By Pauly723 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-30-2014, 03:37 PM
  3. Email each person in excel, including a body of text and attachment
    By memanja in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-12-2014, 10:41 AM
  4. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  5. Email from Excel .... including image stored within Excel Doc (HELP)
    By Thomo88 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2013, 10:54 AM
  6. Create email using excel vba including formatting
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 05-15-2013, 10:16 AM
  7. Including hyperlinks that are clickable from a Excel email using VBA
    By vvebmike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2008, 04:26 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