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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,215,140
Messages
6,123,270
Members
449,093
Latest member
Vincent Khandagale

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