+ Reply to Thread
Results 1 to 6 of 6

code to send email using microsoft windows 10 pro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    code to send email using microsoft windows 10 pro

    Hi, i am having problem with this code below:

    Sub mail()
        Dim OutApp As Object
        Dim OutMail As Object, Recip
        Dim strto, strsub, strbody As String
        Dim myRange, cell As Range
        Dim row As Integer
        Dim ws As Worksheet
        
        
        ThisWorkbook.Save
        
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        Set myRange = Range("A2:A9")
    
        
        strto = "[email protected];[email protected]"
        strsub = "Upcoming expiry and re-orders"
        
        
        
        row = 1
        For Each cell In myRange
        row = row + 1
        If Cells(row, "G").Value = Cells(row, "I").Value And Cells(row, "A").Value <> "" And Cells(row, "J").Value = "" Then
        Cells(row, "J").Value = "Y"
        strbody = "Attention to the following item(s) reaching expiry soon:" & vbCrLf & vbCrLf
        strbody = strbody & Cells(row, "B").Value & " " & "Lot No." & " " & Cells(row, "D").Value & " " & Cells(row, "G").Value & " days left before expiry" & vbCrLf
        End If
        Next cell
        
        row = 1
        For Each cell In myRange
        row = row + 1
        If Cells(row, "F").Value = Cells(row, "H").Value And Cells(row, "A").Value <> "" And Cells(row, "K").Value = "" Then
        Cells(row, "K").Value = "Y"
        strbody = strbody & vbCrLf & "Attention to the following item(s) reaching reorder point:" & vbCrLf & vbCrLf
        strbody = strbody & Cells(row, "B").Value & " " & "Lot No." & " " & Cells(row, "D").Value & " " & Cells(row, "F").Value & " units left" & vbCrLf
        End If
        Next cell
        
        
        If strbody = "" Then
        Exit Sub
        End If
        
        With OutMail
        .To = strto
        .Subject = strsub
        .body = strbody
        .send
        End With
        
        Set OutMail = Nothing
        Set OutApp = Nothing
        
        
    End Sub
    it works fine on my other computer running windows 10 enterprise, so i suspect its the email application that differs (outlook 2016 on my enterprise while it seems like an app in the windows 10 pro).

    Can someone help me with the code please?

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: code to send email using microsoft windows 10 pro

    The code's correct. YOU will have to discover what is different .
    You have not even told us what goes wrong.

    Hi, i am having problem with this code below:
    WHAT is the problem.
    WHAT does not work.

    This is not a guessing game, concise explanation and even the title of your post is VERY vague, you forgot to mention that is applies to Excel

    Try and explain better if you want to receive help
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: code to send email using microsoft windows 10 pro

    sorry about that. This line was highlighted when i run it on windows 10 pro

     Set OutApp = CreateObject("Outlook.Application")

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: code to send email using microsoft windows 10 pro

    I wonder if Outlook is installed ?

  5. #5
    Forum Contributor
    Join Date
    05-06-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    361

    Re: code to send email using microsoft windows 10 pro

    it is. but its different from the one on windows 10 enterprise (Outlook 2016). The windows 10 pro platform uses this Mail app where you can select Outlook as the email account.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: code to send email using microsoft windows 10 pro

    You might need to set the reference in the tools menu inside the VBA editor, check it there.
    Outlook.Application is the actual Outlook that comes with Office 2016 it has nothing to do with Windows 10 whatever version.
    The Outlook App is something else.
    Have you Googled ?

+ 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. 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
  2. Need Send Keys code to send "Windows key + UP arrow"
    By balajinatarajan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2016, 07:51 PM
  3. VBA code to send email to the people whose email address is in the Access table
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2014, 05:11 AM
  4. [SOLVED] VBA Email code creates TWO windows
    By esvenk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2013, 07:32 PM
  5. change event macro to evaluate windows user who initiated the change then send email
    By pmanoloff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2012, 03:31 PM
  6. Replies: 0
    Last Post: 03-08-2012, 11:25 AM
  7. Code to send Email wont send everytime
    By tanktata in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-11-2011, 04:44 PM

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