Export text file with VBA (1 Viewer)

chergh

blah
Local time
Today, 07:17
Joined
Jun 15, 2004
Messages
1,414
The let me google link was a bit mean of me and you have done a lot more for yourself than a lot of people who come to forums.

The sendobject method doesn't actually exist in excel but there is a sendmail method but it's quite limited but it may be enough for you.

Try:

Code:
Public Sub save()
    
Dim path As String

Application.DisplayAlerts = False

path = ThisWorkbook.path & "\" & ThisWorkbook.Name

ThisWorkbook.save

'put your code to combine tabs and delete blank rows in here

ThisWorkbook.SaveAs Filename:="C:\documents and settings\%username%\Desktop\BookName.csv", FileFormat:=xlCSVMSDOS, CreateBackup:=False

thisworkbook.sendmail recipients:= "cbdfw@yahoo.com", subject:= "workbook"

Workbooks.Open path
Application.DisplayAlerts = True
Workbooks("BookName.csv").Close False
End Sub
 

CB_DFW

Registered User.
Local time
Today, 01:17
Joined
Nov 5, 2008
Messages
30
That code worked great. I did some more research and found this code and got it to work also. It provides a few more options such as:
1. allows for multiple recipients and you can add them to the cc: and bcc:
2. does not require the user to allow the email
3. it allows you to email files from your system that were already saved.

Code:
' ' requires a reference to the Microsoft Outlook 8.0 Object Library
Sub SendAnEmailWithOutlook()
Dim desktopPath As String
desktopPath = fGetSpecialFolderLocation(CSIDL_DESKTOPDIRECTORY)
' creates and sends a new e-mail message with Outlook
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
    Set OLF = GetObject("", _
        "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    Set olMailItem = OLF.Items.Add ' creates a new e-mail message
    With olMailItem
        .Subject = "Region 68 CDL Spreadsheet" ' message subject
        Set ToContact = .Recipients.Add("insert email address") ' add a recipient
        Set ToContact = .Recipients.Add("insert email address") ' add a recipient
        ToContact.Type = olCC ' set latest recipient as CC
        'Set ToContact = .Recipients.Add("insert email address") ' add a recipient
        'ToContact.Type = olBCC ' set latest recipient as BCC
        .Body = "Test SendAnEmailWithOutlook" & Chr(13)
        ' the message text with a line break
        .Attachments.Add "C:\R0068 CDL.csv", olByValue, , _
        "Attachment" ' insert attachment
'        .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _
             "Shortcut to Attachment" ' insert shortcut
'        .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _
             "Embedded Attachment" ' embedded attachment
'        .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _
             "OLE Attachment" ' OLE attachment
        '.OriginatorDeliveryReportRequested = True ' delivery confirmation
        '.ReadReceiptRequested = True ' read confirmation
        '.Save ' saves the message for later editing
        .Send ' sends the e-mail message (puts it in the Outbox)
    End With
    Set ToContact = Nothing
    Set olMailItem = Nothing
    Set OLF = Nothing
End Sub
 

Users who are viewing this thread

Top Bottom