+ Reply to Thread
Results 1 to 6 of 6

attach file from folder on c:\ to outlook mail and send

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-01-2012
    Location
    england
    MS-Off Ver
    Excel 2016 pro
    Posts
    772

    attach file from folder on c:\ to outlook mail and send

    hi
    having downloaded and tried about a dozen different codes today im stuck
    i have a xslx book named sheet2 its 3mb , i have tried to attach to email and done this once but it will not send,if i do it manually open email attach and send it work ok but not automatically through vb ,what am i doing wrong,before i merged these together there were 18 files 200kb ,they also populated the email but would not send either,file is sheet2 in "c:\users\colin\desktop\new\"
    any ideas anyone please
    cheers colin
    Last edited by cfinch100; 02-24-2013 at 11:34 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: attach file from folder on c:\ to outlook mail and send

    Colin

    What code have you tried?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-01-2012
    Location
    england
    MS-Off Ver
    Excel 2016 pro
    Posts
    772

    Re: attach file from folder on c:\ to outlook mail and send

    hi norie have tried mostly rondebruin codes for email have few saved on notepad on laptop and various ones off net
    most of them save from active workbook have had few nearly there jaslake gave me one but for some reason populates outlook but sends but does not arrive,but manually it does , like copy then paste attachment into outlook all fine

    code below is from jaslake its saves to folder on c:as book1,book2 ectthen picks them up with mybooksfound,it populated outlook, sends
    but does not arrive again,manually it does,at the minute there are6 books on c:folder ive merged into one but still does not work
    cheers colin






    Public myBooksFound() As Variant
    Option Explicit
    Sub Create_Files()
        Dim wsSh As Worksheet
        Dim MyPath As String
        Dim mySavePath As String
        Dim myBook As String
        Dim FileName As String
        Dim ws As Worksheets
        ReDim myBooksFound(0)
    
        MyPath = "C:\users\colin\Desktop\New\"          '<----Change this
        mySavePath = "C:\users\colin\Desktop\New\Temp\" '<----Change this
    
        On Error Resume Next
        'Kill "C:\Documents and Settings\Administrator\Desktop\New\Temp\*.xls*"  <----Change this
    
        On Error GoTo 0
    
        myBook = Dir(MyPath & "*.xls*")
    
        Do While myBook <> ""
            Workbooks.Open FileName:=MyPath & myBook
    
            For Each wsSh In ActiveWorkbook.Sheets
                If Not wsSh.Name = "Sheet1" Then
                    Application.DisplayAlerts = False
                    wsSh.Delete
                    Application.DisplayAlerts = True
                End If
                FileName = ActiveWorkbook.Name
                Application.DisplayAlerts = False
                ActiveWorkbook.SaveAs FileName:=mySavePath & FileName
                Application.DisplayAlerts = True
            Next
            myBooksFound(UBound(myBooksFound)) = mySavePath & myBook
            ReDim Preserve myBooksFound(UBound(myBooksFound) + 1)
            Workbooks(myBook).Close SaveChanges:=False
            myBook = Dir
        Loop
        ReDim Preserve myBooksFound(UBound(myBooksFound) - 1)
    
        Call Mail_Sheets_Array
    
    End Sub
    
    Sub Mail_Sheets_Array()
        Dim Sourcewb As Workbook
        Dim OutApp As Object
        Dim OutMail As Object
        Dim i As Long
    Dim ws As Worksheets
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        Set Sourcewb = ActiveWorkbook
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = "colin.finch17@sky.com"
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Hi therehu colin"
    
            For i = 0 To UBound(myBooksFound)
                .attachments.Add myBooksFound(i)
            Next
    
            .Display
            '            .Send   'or use .Display
        End With
        
         On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        
        
        
         
       ' Kill "c:\users\colin\desktop\new\temp\*.xlsx*"
       ' Kill "c:\users\colin\desktop\new\*.xlsx*"
       ' Set ws = Worksheets("completed")
    'Sheet6.Cells.ClearContents
        
    End Sub

  4. #4
    Forum Contributor
    Join Date
    10-01-2012
    Location
    england
    MS-Off Ver
    Excel 2016 pro
    Posts
    772

    Post Re: attach file from folder on c:\ to outlook mail and send

    hi norie
    have sent you program see if you can send email with it then i know its this end dont no why it wont,have just done it
    through sky manually 18 files and works
    start it up click reports
    enter 2 in ainscough ref click search
    says theres 18click email contracts
    click print contracts
    and should populate out look
    needs new folder on c:
    and temp folder in new folder
    cheers colin
    Attached Files Attached Files

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: attach file from folder on c:\ to outlook mail and send

    Colin

    Have you tried just sending one email instead of a whole bunch?

    Have you checked if there are any settings in Outloook that could be causing the problem?

    How many attachments are you sending?

  6. #6
    Forum Contributor
    Join Date
    10-01-2012
    Location
    england
    MS-Off Ver
    Excel 2016 pro
    Posts
    772

    Re: attach file from folder on c:\ to outlook mail and send

    hi norie
    have just got it working fingers crossed looks like outlook and my sky email not set up properly together so looks like now works will check it on work computer
    mon,new it could not be much as it worked for jaslake but not me
    thanks for reply
    cheers colin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1