VBA Question - Can this be done easily?

Mich6661

New Member
Joined
Aug 1, 2013
Messages
19
I need some assistance please all.

I have around 100 excel files that need to be emailed out every 2 days.
I have just lost my admin resource and don't have time to do this manually.

Is there a way, using a defined address book or list of email addresses to create a macro that matches the email address to the file number and will send it automatically?

If not, can anyone recommend an alternative solution? (Pls don't say hire a new admin!! :LOL:

Many thanks
Mich....
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Do you send the excel file or a PDF of it?
If excel file is the file protected or not?
Are all files in the same directory?
Are they excel worksheets or workbooks? In other words are all this excel file a separate workbook or a single file with many worksheets?
 
Upvote 0
Do you send the excel file or a PDF of it?
If excel file is the file protected or not?
Are all files in the same directory?
Are they excel worksheets or workbooks? In other words are all this excel file a separate workbook or a single file with many worksheets?

Hi
It will be excel files that are to be sent There will be 1 file per email address group.
The excel files are not protected and are all in the same directory.
There are around 100 individual files

thx
Mich
 
Upvote 0
If you use Outlook, open up a new Excel workbook, and set up Sheet1 like this:

AB
1NameFile
2bob@somewhere.comC:\MyFiles\Status\File1.xlsx
3Jane@somewhere.comC:\MyFiles\Status\File2.xlsx
4

<tbody>
</tbody>
Sheet1

I suspect you can change the actual email address to a group name, although I haven't tried it.

Then press Alt-F11 to open then VBA editor. From the menu, select Insert > Module. Then paste the following code into the window that opens:
Rich (BB code):
Sub Mail_Workbooks()
Dim OutApp As Object, OutMail As Object, WS As Worksheet, r As Long


    Set OutApp = CreateObject("Outlook.Application")
    
    Set WS = Sheets("Sheet1")
    On Error Resume Next


    For r = 2 To WS.Cells(Rows.Count, "A").End(xlUp).Row
    
        With OutApp.CreateItem(0)
            .To = WS.Cells(r, 1).Value
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Hi there"
            .Attachments.Add WS.Cells(r, 2).Value
            .Send
        End With
        DoEvents
    Next r
    
    On Error GoTo 0
    Set OutApp = Nothing
End Sub
Change the parts in red to what you want. Then press Alt-Q to close the editor.

Now just keep Sheet1 updated. The macro will read to the last used row. To run it, press Alt-F8, select Mail_Workbooks and press Run.
 
Last edited:
Upvote 0
If you use Outlook, open up a new Excel workbook, and set up Sheet1 like this:

AB
1NameFile
2bob@somewhere.comC:\MyFiles\Status\File1.xlsx
3Jane@somewhere.comC:\MyFiles\Status\File2.xlsx
4

<tbody>
</tbody>
Sheet1

I suspect you can change the actual email address to a group name, although I haven't tried it.

Then press Alt-F11 to open then VBA editor. From the menu, select Insert > Module. Then paste the following code into the window that opens:
Rich (BB code):
Sub Mail_Workbooks()
Dim OutApp As Object, OutMail As Object, WS As Worksheet, r As Long


    Set OutApp = CreateObject("Outlook.Application")
    
    Set WS = Sheets("Sheet1")
    On Error Resume Next


    For r = 2 To WS.Cells(Rows.Count, "A").End(xlUp).Row
    
        With OutApp.CreateItem(0)
            .To = WS.Cells(r, 1).Value
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Hi there"
            .Attachments.Add WS.Cells(r, 2).Value
            .Send
        End With
        DoEvents
    Next r
    
    On Error GoTo 0
    Set OutApp = Nothing
End Sub
Change the parts in red to what you want. Then press Alt-Q to close the editor.

Now just keep Sheet1 updated. The macro will read to the last used row. To run it, press Alt-F8, select Mail_Workbooks and press Run.


Thanks for this. copied all across and i can get it to send the email but not the attachment.

Regards
Mich
 
Upvote 0
Make sure that the file names are correct. Full path name. Also, the separators should be a backslash, not a pipe character. When you quoted my post, it shows as a pipe, but that could be a result of the forum software. You can try changing

.Send

to

.Display

to see if there's something about that email. Other than those ideas, I'm not sure what to tell you, it works for me.
 
Upvote 0
Hi Eric

It worked perfectly once i got round the security on our servers.
Thank you so much, it has certainly saved on admin.

Much appreciated :)
 
Upvote 0

Forum statistics

Threads
1,216,773
Messages
6,132,633
Members
449,740
Latest member
tinkdrummer

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