Add workbook and automatic dispatch via mail

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Good morning.

I'm working on this stuff with the help of the macro recorder. But clearly it's not exaustive for specific needs.

I've a workbook named "source".
Starting from a sheet named "last" of this workbook, I've to generate a new workbook with some datas and sending it in csv format to e-mail adresses via Microsoft Outlook.

This is my work with the macro recorder.



Code:
Sub sent_mail()

    Workbooks.Add 'open a new workbook'
    Sheets("Sheet2").Select 'delete useless sheets, maybe not necessary'
    ActiveWindow.SelectedSheets.Delete
    Sheets("Sheet3").Select
    ActiveWindow.SelectedSheets.Delete
    ChDir "C:\Users\john.smith\Desktop"
    ActiveWorkbook.SaveAs Filename:="C:\Users\john.smith\Desktop\example.csv" _
        , FileFormat:=xlCSV, CreateBackup:=False 'save with name example'
    
    Windows("source.xlsm").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy 'copy needed datas'
    Windows("example.csv").Activate
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False 'past needed datas on csv new workbook'
    Application.CutCopyMode = False 
    
    Application.Dialogs(xlDialogSendMail).Show 
    
End Sub

Furthermore, I've to name the new workbook using one cell of the "source" workbook. The cell is B2 in a sheet called "test".

The e-mail adresses that have to receive the mail are: "frank@example.com" and "mark@example.com"

Thank you.
 
Last edited:
That would be my guess, and it's clearly just a guess. Does your other software not give you any hints as to why a particular import fails?

No problems in the following days.
Spooky. Most probably it's my fault, but i've not understood how to prevent it.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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