Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel vba to attach workbooks to a spreadsheet

    I have written code that successfully sends text emails by going down each line in a worksheet and sending reports to the addresses listed on each row. I now need to extend this code to attach excel work books to each email. The code attached attempts to attach a single workbook to each email and then send it. I have anotated those lines that work and fail. Can somebody please assist with: Query 1: I would like to define the workbook that is to be attached to the email, without opening the workbook first - my code of Set WBAttachment = Workbooks(filestring) fails unless the workbook is open. Query 2: I need some revised code that allows me to correctly attach the workbook to the email within the emailing function. Query 3: Ideally I would like to attach multiplle workbooks to a single email - can somebody please advise how to achieve this. Thanks Alex
    Attached Files Attached Files

  2. #2
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update

    I have now found that I should use the code .attachments.add (filepath of item to be added) Instead of Attachments = .... However I have now encountered a further problem. I keep on getting a run time error on the attachment.add line, telling me that the item to be attached has been moved or deleted. Therefore I placed a test Workbooks.Open (Same file path as attachment) just before the Attachments. add line. Excel happily opened the workbook on ine 1, but then encountered an error when trying to attach it on line 2. Any suggestions on how to solve this would be appreciated. Thanks Alex

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update 2

    This problem is now solved. It helps if you do not send the email before you add the attachment...

Posting Permissions

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