Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Email files using macro
I would like to email multiple files to multiple users using a macro.
I have created a macro that can send one file to multiple users using a default mesaage, but am having difficulty sending more than one file to more than one user. In addition, part of the the file name changes each (the date element, the prefix / ext stay the same. Ideally, I would like to incorporate a subject and a message for the email besides attaching the file/s. Here is the current macro which includes a progress bar and a subject but no message: Sub ProgressBar3(Msg1 As String, PctDone1 As Single) With ProgressDlg3 .lblMessage.Caption = Msg1 .lblDone.Width = PctDone1 * (.lblRemain.Width - 2) .lblPct.Caption = Format(PctDone1, "0%") '.lblMessage2.Caption = Msg2 '.lblDone2.Width = PctDone2 * (.lblRemain2.Width - 2) '.lblPct2.Caption = Format(PctDone2, "0%") End With 'The DoEvents statement is responsible for the form updating DoEvents End Sub Sub CommandButton1_Click() Dim email(20) As String 'initialize the array to 20 rather than bothering to code a redim later Dim x As Integer Dim p As Integer, totP As Integer, totE As Integer Application.DisplayAlerts = True ' Turns ON display alerts Application.ScreenUpdating = True ' Turns ON screen updating Application.StatusBar = False Workbooks.Open Filename:=Cells(1, 3) 'set the file you want to send here. totE = 1 'load address array from spreadsheet While Cells(totE, 1) < "" email(totE) = Cells(totE, 1) 'MsgBox "loaded " & totE & " as " & Cells(totE, 1) totE = totE + 1 Wend Load ProgressDlg3 ProgressDlg3.Show vbModeless e = 1 totP = 14 ' number of pictures in animation p = 0 On Error Resume Next ' ignore error if pictures are not found ProgressDlg3.Image1.Picture = LoadPicture(ThisWorkbook.Path & "\mail" & p & ".gif") On Error GoTo 0 ProgressDlg3.Caption = "Sending e-mail" For e = 1 To totE - 1 p = p + 1 If p totP Then p = 1 On Error Resume Next ' ignore error if pictures are not found ProgressDlg3.Image1.Picture = LoadPicture(ThisWorkbook.Path & "\mail" & p & ".gif") On Error GoTo 0 If e Mod 1 = 0 Then ProgressBar3 email(p), e / totE End If ActiveWorkbook.SendMail Recipients:=email(e), Subject:="Data File" Next e Unload ProgressDlg3 MsgBox e - 1 & " emails sent", vbInformation Workbooks("data.xls").Close SaveChanges:=True ' Saves & Closes File. Windows("datafile.xls").Activate ' Switch Window & Return to Sheets("Macro Control").Select ' Macro Contol Tab End Sub __________________________________________________ __________ Any help would be greatly appreciated. Thanks In advance.. David |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Using Macro how to create email link for the email addresses in aRange or Selection | Excel Worksheet Functions | |||
Macro to split excel file into seperate files and then email | Excel Discussion (Misc queries) | |||
Email files | Excel Worksheet Functions | |||
How do I create an email macro to auto fill the email? | Excel Discussion (Misc queries) | |||
I can not email excel files | New Users to Excel |