Error message 440

Phil60

New Member
Joined
Mar 8, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
HI everybody,

I am new to vba. I try to send an active workbook " order template" via mail but I keep getting error message 440. Can somebody tell me what I am doing wrong.

Thansk for helping
VBA Code:
Dim objoutlook As Object
    Set objoutlook = CreateObject("outlook.application")
    Dim objemail As Object
    Set objemail = objoutlook.createitem(olmailitem)
    With objemail
     .to = "[EMAIL]xxxx@live.com[/EMAIL]"
     .Subject = "Bestelling Techniek"
     .body = "beste"
     .Attachments = ThisWorkbook
                  .display
    End With


    Range("A2:I300").Select
    Selection.ClearContents
  
End Sub
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the forum. :)

This line:

Code:
.Attachments = ThisWorkbook

should be:

Code:
.Attachments.Add ThisWorkbook.Fullname
 
Upvote 0
Solution
Thanks so much!
You are making my day!
:)
HI ,

It is sending the file ok but the basic file(empty) not the one on the screen.
Can you tell me what I have to change in the code to send the file which is active, not the basic template.
The idea is that people can fill in this orderform. Push on the send button, and it automatically is mailed to procurement department which can take action based on this template. Afterwards the template is cleared and available for a new order to be placed.

Thanks for your help
 
Upvote 0
You need to save the file otherwise the information won't be there. Then send the saved workbook instead. I'm assuming the code is in the workbook you want to send?
 
Upvote 0
You need to save the file otherwise the information won't be there. Then send the saved workbook instead. I'm assuming the code is in the workbook you want to send?
I changed the code as follows and now it works.

ActiveWorkbook.Save
Dim objoutlook As Object
Set objoutlook = CreateObject("outlook.application")
Dim objemail As Object
Set objemail = objoutlook.createitem(olmailitem)
With objemail
.to = "philippe.siau@henco.be"
.Subject = "Bestelling Techniek"
.body = "beste"
.Attachments.Add ThisWorkbook.FullName
.display
End With






Range("A2:I300").Select
Selection.ClearContents

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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