vba message box

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
676
Office Version
  1. 365
Platform
  1. Windows
hi
i am trying to have a message box then take user directly to email upon the problem what am i doing wrong?

red text works and creates the message, black text isnt working. also i only want an ok not ok/cancel

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Column = 5 Then
If Target.Value = "_Approval Missing" Then

MsgBox "Notify the boss", vbOKCancel


If MsgBox = vbCancel Then SaveUI = True
If MsgBox = vbOK Then
'open outlook type stuff
Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)
'add recipients
'newmsg.Recipients.Add ("Insert name")
newmsg.Recipients.Add ("name@emailaddress")
'add subject
newmsg.Subject = "Missing Approval"
'add body
newmsg.Body = "Updated document." & vbCrLf & "" & "Please getb approval"
newmsg.Display 'display
newmsg.Send 'send message
'give conformation of sent message
MsgBox "Outlook message sent", , "Outlook message sent"


End If
End If
End Sub
 
no
doesnt work says type mismatch
when available can you please help with this final twaek of the code
otherwise it is amazing
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 And Target.Column = 5 Then
    If Target.Value = "_Approval Missing" Then
        result = MsgBox("Notify the boss", vbOKCancel)
        If result = vbCancel Then SaveUI = True
        If result = vbOK Then

            Set OutlookApp = CreateObject("Outlook.Application")
            Set OlObjects = OutlookApp.GetNamespace("MAPI")
            Set newmsg = OutlookApp.CreateItem(olMailItem)

            newmsg.Recipients.Add ("john.doe@abcd.com.au ") ' Add Recipients
            newmsg.Subject = "Missing Approval"  ' Add Subject
            newmsg.Body = "Updated document." & vbCrLf & "" & _
                          "Please get approval by   " & _
                          Target.Cells.Offset(0, -4).Value & _
                          " for Reference no:   " & _
                          Target.Cells.Offset(0, 1).Value ' Email Body
            newmsg.Display   'Display Email
            newmsg.Send      'Send Email

            MsgBox "Outlook message sent", , "Outlook message sent"  ' Confirm Sent Email


        End If
        End If
    End If

End Sub
 
Upvote 0
you guys are amazing. this is perfect
may you be blessed with health and all good
stay safe
 
Upvote 0
how do i chose button vb exclamation ok/cancel
 
Upvote 0
did it with the + symbol
thanks
this is magic
 
Upvote 0
1-can my email be sent to more than one e-mail address, how can i enter all the addresses?
2- what if the reply i am looking for is a ✔ in BOTH columns G and H then reply yes of message box sends email value of column A "is ready to launch"
 
Upvote 0
whats wrong?


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 And Target.Column = 6 and Target.Column = 7 Then
If Target.Value = "✔" Then
result = MsgBox("pressing OK will send email to notify", vbOKCancel + vbExclamation, "can launchl")
If result = vbCancel Then SaveUI = True
If result = vbOK Then

Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)

newmsg.Recipients.Add ("mail@mail.org") ' Add Recipients
newmsg.Subject = "can launchl" ' Add Subject
newmsg.Body = "launch" & vbCrLf & "" & _
"Please schedule launch for " & _
Target.Cells.Offset(0, 1).Value ' Email Body
newmsg.Display 'Display Email
newmsg.Send 'Send Email

MsgBox "Outlook message sent", , "Outlook message sent" ' Confirm Sent Email


End If
End If
End If

End Sub
 
Upvote 0
this code worked really well however the email needs to give me the information in the same row of column 6
however, the code and message box and email run as soon as _Approvals missing is entered in column 5 before the class name is entered in column 6.
is there a way to wait for column 6 to be populated before the code runs?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 And Target.Column = 5 Then
    If Target.Value = "_Approval Missing" Then
        result = MsgBox("Notify the boss", vbOKCancel)
        If result = vbCancel Then SaveUI = True
        If result = vbOK Then

            Set OutlookApp = CreateObject("Outlook.Application")
            Set OlObjects = OutlookApp.GetNamespace("MAPI")
            Set newmsg = OutlookApp.CreateItem(olMailItem)

            newmsg.Recipients.Add ("john.doe@abcd.com.au ") ' Add Recipients
            newmsg.Subject = "Missing Approval"  ' Add Subject
            newmsg.Body = "Updated document." & vbCrLf & "" & _
                          "Please get approval by   " & _
                          Target.Cells.Offset(0, -4).Value & _
                          " for Reference no:   " & _
                          Target.Cells.Offset(0, 1).Value ' Email Body
            newmsg.Display   'Display Email
            newmsg.Send      'Send Email

            MsgBox "Outlook message sent", , "Outlook message sent"  ' Confirm Sent Email


        End If
        End If
    End If

End Sub
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 And Target.Column = 5 Then
    If Target.Value = "_Approval Missing" Then
        result = MsgBox("Notify the boss", vbOKCancel)
        If result = vbCancel Then SaveUI = True
        If result = vbOK Then

            Set OutlookApp = CreateObject("Outlook.Application")
            Set OlObjects = OutlookApp.GetNamespace("MAPI")
            Set newmsg = OutlookApp.CreateItem(olMailItem)

            newmsg.Recipients.Add ("john.doe@abcd.com.au ") ' Add Recipients
            newmsg.Subject = "Missing Approval"  ' Add Subject
            newmsg.Body = "Updated document." & vbCrLf & "" & _
                          "Please get approval by   " & _
                          Target.Cells.Offset(0, -4).Value & _
                          " for Reference no:   " & _
                          Target.Cells.Offset(0, 1).Value ' Email Body
            newmsg.Display   'Display Email
            newmsg.Send      'Send Email

            MsgBox "Outlook message sent", , "Outlook message sent"  ' Confirm Sent Email


        End If
        End If
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,825
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top