Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
a a is offline
external usenet poster
 
Posts: 51
Default Sending email with VBA - application.displayalerts question

Hi,

Ron de Bruin gave me the following code for emailing files.

It works great! My only problem is that when I run the code, I get an
alert asking me whether I want to send the file. I try using
application.displayalerts = false, but then I don't get an alert but the
mail also doesn't send.

Is there a work around for this.

Thanks in advance for any help.

Anita



Sub TestFile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range
Dim monthAndYear
monthAndYear = InputBox("What is the month and year",
"MonthAndYear", "CY05Q01")

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")



On Error GoTo cleanup
For Each cell In
Sheets("Sheet1").Columns("B").Cells.SpecialCells(x lCellTypeConstants)
If cell.Offset(0, 1).Value < "" Then
If cell.Value Like "?*@?*.?*" And Dir(cell.Offset(0,
1).Value) < "" Then
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.CC = cell.Offset(0, 3)
.Subject = "Variance Reports for " & monthAndYear
.Body = "Hi " & cell.Offset(0, -1).Value & "," &
Chr(10) & Chr(10) & "Attached are your files for " & monthAndYear & ". " _
& "Please let me know if you have any questions." &
Chr(10) & Chr(10) & "Take care," & Chr(10) & "Anita"
.Attachments.Add cell.Offset(0, 1).Value
.Attachments.Add cell.Offset(0, 2).Value
.Application.DisplayAlerts = False
' .Display
.Send 'Or use Display
End With

Set OutMail = Nothing
End If
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Sending email with VBA - application.displayalerts question

Hi

See
http://www.rondebruin.nl/mail/prevent.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl



"a" wrote in message ink.net...
Hi,

Ron de Bruin gave me the following code for emailing files.

It works great! My only problem is that when I run the code, I get an alert asking me whether I want to send the file. I try
using application.displayalerts = false, but then I don't get an alert but the mail also doesn't send.

Is there a work around for this.

Thanks in advance for any help.

Anita



Sub TestFile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range
Dim monthAndYear
monthAndYear = InputBox("What is the month and year", "MonthAndYear", "CY05Q01")

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")



On Error GoTo cleanup
For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(x lCellTypeConstants)
If cell.Offset(0, 1).Value < "" Then
If cell.Value Like "?*@?*.?*" And Dir(cell.Offset(0, 1).Value) < "" Then
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.CC = cell.Offset(0, 3)
.Subject = "Variance Reports for " & monthAndYear
.Body = "Hi " & cell.Offset(0, -1).Value & "," & Chr(10) & Chr(10) & "Attached are your files for " &
monthAndYear & ". " _
& "Please let me know if you have any questions." & Chr(10) & Chr(10) & "Take care," & Chr(10) & "Anita"
.Attachments.Add cell.Offset(0, 1).Value
.Attachments.Add cell.Offset(0, 2).Value
.Application.DisplayAlerts = False
' .Display
.Send 'Or use Display
End With

Set OutMail = Nothing
End If
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application quit without displayalerts Hari[_3_] Excel Programming 3 June 10th 04 08:17 AM
application.displayalerts is not working will lam Excel Programming 2 April 30th 04 08:21 PM
Application.DisplayAlerts in IE scoobydeux Excel Programming 1 April 19th 04 01:28 AM
Application::DisplayAlerts not working Howard Dierking Excel Programming 2 February 11th 04 12:04 PM
application.displayalerts Erin[_5_] Excel Programming 1 December 4th 03 03:49 PM


All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"