Community discussion forum

one button email to:

Tags: vba Malaysia
  • 1 year ago

    hey guys... need your help

    im using ms excel for a simple time stamp (attandance) thingy. i want to have a button where OnClick event it will automatically send the file as attachment via outlook email.

    any macro scipts

  • 1 year ago

    Hi

    Add a reference to Microsoft Excel.

    Try the following.

    Sheets("Sheet1").Select
     
    dname = Range("B1").Value 'defines data for subject

    Dim objol As New Outlook.Application
    Dim objmail As MailItem
    Set objol = New Outlook.Application
    Set objmail = objol.createitem(olmailitem)
       With objmail
           .To = "whoever" 'enter in here the email address
           .cc = "whoever" 'enter in here the email address
           .Subject = "Daily test email for  " & dname
           .Body = "Please find attached the teste email" & _
               vbCrLf & "If you have any queries can you please let me know" & vbCrLf
           .NoAging = True
           .Attachments.Add ThisWorkbook.FullName 'adds attachment to email
           .display
       End With
       Set objmail = Nothing
       Set objol = Nothing
       SendKeys "%{s}", True 'send the email without prompts

  • 1 year ago

    hey thanks for the reply.

    but i have a problem. how do i set the code in the macro? coz it says user defined type is not identified

     [quote user="Jugatsu"]Dim objol As New Outlook.Application[/quote]

    please guide in detail.

    thanks in advace

  • 1 year ago

    Click Tools
     - References
     - Tick Microsoft Outlook 10.0 Object Library
       ( or similar, outlook needs to be installed)

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!