vba warning message

Katy I

New Member
Joined
Jun 21, 2012
Messages
44
I have this code

Code:
Option Explicit
Sub RunOnAll()

Dim sh As Object
Set sh = ActiveSheet.Shapes.AddShape(msoShapeCloud, 125.25, 30, 118.5, 96.75)
sh.Name = "Popup"
ActiveSheet.Shapes("Popup").Select
Selection.Characters.Text = "Running Macro..."
Selection.Font.Size = "24"

With Selection.Characters.Font
    .ColorIndex = xlAutomatic
End With

Dim myPicture As Shape
     
    Set myPicture = ActiveSheet.Shapes("Popup")
     
    With ActiveWindow.VisibleRange
        myPicture.Top = .Top + .Height / 2 - myPicture.Height / 1
        myPicture.Left = .Left + .Width / 6 - myPicture.Width / 60
        myPicture.Height = myPicture.Height * 3
        myPicture.Width = myPicture.Width * 3
        
        Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 49
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 45
        End With
    myPicture.Visible = True
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        Mail_small_Text_Outlook ws
    Next ws
    myPicture.Delete
    
    Dim sha As Object
Set sha = ActiveSheet.Shapes.AddShape(msoShapeSmileyFace, 125.25, 30, 118.5, 96.75)
sha.Name = "Popu"
ActiveSheet.Shapes("Popu").Select
Selection.Characters.Text = "Done!"
Selection.Font.Size = "30"
With Selection.Characters.Font
    .ColorIndex = "2"
End With

Dim myPic As Shape
     
    Set myPic = ActiveSheet.Shapes("Popu")
     
    With ActiveWindow.VisibleRange
        myPic.Top = .Top + .Height / 2 - myPic.Height / 1
        myPic.Left = .Left + .Width / 6 - myPic.Width / 60
        myPic.Height = myPic.Height * 3
        myPic.Width = myPic.Width * 3
        
        Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 57
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 61
        End With
    myPic.Visible = True
    
    
End Sub
 
Sub Mail_small_Text_Outlook(ws As Worksheet)
Dim cell As Range
Dim OutApp As Object
Dim OutMail As Object
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    On Error GoTo cleanup
    For Each cell In ws.Columns("G").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" And _
           LCase(ws.Cells(cell.Row, "H").Value) = "y" Then
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            
            
            With OutMail
                .To = cell.Value
                .Subject = "Request for Quotation"
                .Body = "Dear " & ws.Cells(cell.Row, "F").Value _
                        & vbNewLine & vbNewLine & _
                        "Please review the attachment and " & _
                        "let us know your quote."
                .Attachments.Add ("T:\KATY IKEDA\KATY IKEDA\request for quote.xls")
                
                .Display
            End With
            
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
 
 
    
End Sub

It runs through a list of companies and emails an attachment to each company selected. But I do not have an email address for certian companies. Is there a way to make it send the emails to the companies we do have and have a message pop up listing the companies that didn't have email adresses?

Thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try,
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]If Trim(cell.Value) <> "" And cell.Value Like "?*@?*.?*" And _[/COLOR][/SIZE][/FONT]
instead of
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]If cell.Value Like "?*@?*.?*" And _[/COLOR][/SIZE][/FONT]
 
Upvote 0
Sorry, I should have mentioned I am very new to VBA. I cannot get anything to pop up with that code. Where should I put the error message I want to pop up?

Thank you for your help!
 
Upvote 0
It's OK, try this, the Greenstatements are the new/modified ones
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Sub Mail_small_Text_Outlook(ws As Worksheet)

    Dim Cell As Range
    Dim OutApp As Object
    Dim OutMail As Object
    [COLOR="Green"]Dim sCompaniesList As String[/color]

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    On Error GoTo cleanup
    For Each Cell In ws.Columns("G").Cells.SpecialCells(xlCellTypeConstants)
        [COLOR="Green"]If Trim(Cell.Value) <> "" And Cell.Value Like "?*@?*.?*" And _[/color]
            LCase(ws.Cells(Cell.Row, "H").Value) = "y" Then
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = Cell.Value
                .Subject = "Request for Quotation"
                .Body = "Dear " & ws.Cells(Cell.Row, "F").Value _
                        & vbNewLine & vbNewLine & _
                        "Please review the attachment and " & _
                        "let us know your quote."
                .Attachments.Add ("T:\KATY IKEDA\KATY IKEDA\request for quote.xls")
                .Display
            End With
            
            On Error GoTo 0
            Set OutMail = Nothing
        [COLOR="Green"]Else
            sCompaniesList = IIf(sCompaniesList = "", Cell.Value, vbmewline & Cell.Value)[/color]
        End If
    Next Cell
    [COLOR="Green"]MsgBox sCompaniesList, vbInformation, "List of companies having no e-mail address"[/color]

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0
It's OK, try this, the Green statements are the newly added/modified ones
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Sub Mail_small_Text_Outlook(ws As Worksheet)

    Dim Cell As Range
    Dim OutApp As Object
    Dim OutMail As Object
    [COLOR="Green"]Dim sCompaniesList As String[/color]

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    On Error GoTo cleanup
    For Each Cell In ws.Columns("G").Cells.SpecialCells(xlCellTypeConstants)
        [COLOR="Green"]If Trim(Cell.Value) <> "" And Cell.Value Like "?*@?*.?*" And _[/color]
            LCase(ws.Cells(Cell.Row, "H").Value) = "y" Then
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = Cell.Value
                .Subject = "Request for Quotation"
                .Body = "Dear " & ws.Cells(Cell.Row, "F").Value _
                        & vbNewLine & vbNewLine & _
                        "Please review the attachment and " & _
                        "let us know your quote."
                .Attachments.Add ("T:\KATY IKEDA\KATY IKEDA\request for quote.xls")
                .Display
            End With
            
            On Error GoTo 0
            Set OutMail = Nothing
        [COLOR="Green"]Else
            sCompaniesList = IIf(sCompaniesList = "", Cell.Value, vbNewLine & Cell.Value)[/color]
        End If
    Next Cell
    [COLOR="Green"]MsgBox sCompaniesList, vbInformation, "List of companies having no e-mail address"[/color]

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0
Sorry, I may have spoked too soon. The error message pops up but it opens up about 30 times before it will go away. Any ideas on why this may be happening?
 
Upvote 0
How many times you call the macro Mail_small_Text_Outlook()?
Did you copy the modified code and pasted over the old one or you added the new lines by yourself?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,203,052
Messages
6,053,223
Members
444,648
Latest member
sinkuan85

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