Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Edit:</p> <p>Oops I misread your sub name. </p> <p>You should add this to the top of your module, to help yourself in the future.</p> <pre><code>Option Explicit </code></pre> <p>This updated suggestion actually runs. </p> <p>Your code: Private Sub CommandButton1_Click() send email End Sub</p> <p>Should read:</p> <pre><code>Private Sub CommandButton1_Click() sendmail End Sub </code></pre> <p>Note the change from send email to sendmail.</p> <p>Additionally:</p> <pre><code>Set apps = CreateObject("Outlook.Application") Set itm = app.createitem(0) </code></pre> <p>Should read</p> <pre><code>Set apps = CreateObject("Outlook.Application") Set itm = apps.createitem(0) </code></pre> <p>Note the missing s. Without that s, the code will error right after with itm.</p> <p>Edit 2:</p> <p>Perhaps it's easier to show you what I mean. When you use option explicit, you must explicitly declare your variables. The pro is that you will not be able to use variables that you have not declared which will keep you from using app when you meant apps for example.</p> <p>Here is corrected version of your script:</p> <pre><code>Option Explicit Private Sub CommandButton1_Click() sendmail End Sub Public Function sendmail() On Error GoTo ende Dim esubject As String, sendto As String, ccto As String, ebody As String, newfilename As String Dim apps As Object, itm As Object esubject = "Systematic and Manually Created ASN" sendto = "oo@hp.com" ccto = "rt@hp.com" ebody = "Hello All" &amp; vbCrLf &amp; _ "Please find the Systematically and Manually created ASN for the last month" &amp; _ vbCrLf &amp; "With Regards" &amp; vbCrLf &amp; "Tarak" newfilename = "C:\Stuff.XLS" Set apps = CreateObject("Outlook.Application") Set itm = apps.createitem(0) With itm .Subject = esubject .To = sendto .cc = ccto .body = ebody .attachments.Add (newfilename) .display .Send End With Set apps = Nothing Set itm = Nothing ende: End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload