Thanks Thanks:  0
Likes Likes:  0
Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: E-mailing a Workbook as an attachment, but...

  1. #11
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I think the problem lies in the olMail.Attachments.Add ThisWorkbook.FullName statement. How to I reword this to send the active sheet. I tried Windows("Book1").Activate and then sending it, but it errored. Do I need to specify the actual name of the file somewhere?

    Try
    Activeworkbook.fullname

    Ivan

  2. #12
    Board Regular
    Join Date
    Mar 2002
    Location
    Tulsa, OK
    Posts
    319
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default


    No-go. A Run time Error occurs:

    "System cannot find the file specified."

    See the frustration I have been going through?
    - Jim

    (Office 365)


    "Working on mysteries without any clues..."

  3. #13
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    The code will only work if the activeworkbook has been saved. This modified code will check to see if it has. If not, it will prompt the user to save the file.

    HTH,
    D

    Code:
    Sub SendAWorkbook()
    'Sends active workbook from Outlook without saving in Sent Items
    
    'References need to the MS Outlook object library
    
    Dim olApp As Outlook.Application
    Dim olMail As Outlook.MailItem
    Dim strWorkbookPath As String
    
    
    'Test to see if the active workbook has been saved before.  It'll need to be before it can be sent
    
    If ActiveWorkbook.Path = "" Then
        MsgBox "Workbook must be saved before it can be sent.", vbExclamation, "Cannot send workbook"
        strWorkbookPath = Application.GetSaveAsFilename(, "Microsoft Excel Workbook,*.xls")
        
        If strWorkbookPath = "False" Then
            MsgBox "Workbook will not be sent.", vbInformation, "Cannot send workbook"
            Exit Sub
        End If
        
        ActiveWorkbook.SaveAs strWorkbookPath
    End If	
    
    'Create Outlook application and send the mail
    Set olApp = New Outlook.Application
    Set olMail = olApp.CreateItem(olMailItem)
    olMail.To = "someone@somewhere.com;someoneelse@somewhereelse.co.uk"
    olMail.Attachments.Add ActiveWorkbook.FullName
    olMail.Subject = "Sent automatically"
    olMail.DeleteAfterSubmit = True
    olMail.Send
    End Sub

  4. #14
    Board Regular
    Join Date
    Mar 2002
    Location
    Tulsa, OK
    Posts
    319
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    dk:

    That worked like a charm!

    Thank you for all your help!
    - Jim

    (Office 365)


    "Working on mysteries without any clues..."

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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