<\/a>Send workbook as attachment<\/p><\/div> \nHere in this article, you will learn how to send the ActiveWorkbook as an attachment. There could be two ways of sending the same workbook as an attachment – \n \n1) Send the Last saved version of the workbook as an attachment. \n2) First Save as the ActiveWorkbook at a temporary location with a given name and then attach it to mail and send it. After sending the email, delete the temporary file saved. \n<\/p>\n
1) 1st Method:<\/h2>\n In this method you can simply attach the Last saved version of the workbook as an attachment and mail will be sent. But if you want a different name and some modification in the workbook (WHICH HAS TO BE SENT) then follow the 2nd Method <\/strong> given below. \n<\/p>\n\n\nSub Email_CurrentWorkBook()\n\n 'Do not forget to change the email ID\n 'before running this code\n Dim OlApp As Object\n Dim NewMail As Object\n\n Set OlApp = CreateObject(\"Outlook.Application\")\n Set NewMail = OlApp.CreateItem(0)\n\n On Error Resume Next\n With NewMail\n .To = \"info@learnexcelmacro.com\"\n .CC = \"info@learnexcelmacro.com\"\n .BCC = \"info@learnexcelmacro.com\"\n .Subject = \"Type your Subject here\"\n .Body = \"Type the Body of your mail\"\n .Attachments.Add ActiveWorkbook.FullName\n .Send 'or use .Display to show you the email before sending it.\n End With\n On Error GoTo 0\n\n Set NewMail = Nothing\n Set OlApp = Nothing\nEnd Sub\n\n<\/code><\/pre>\n<\/p>\n
1) 2nd Method: <\/h2>\n In this Method, we are following the following method:<\/p>\n
Step 1.<\/strong> First Save the ActiveWorkbook at a temporary location with a given name. You can modify details if you wish, in this copy, because this is the copy we are going to send in email as an attachment. By doing so, your original workbook will remain unchanged. \nStep 2.<\/strong> Attach this Temporary file in the email as an attachment and send email. \nStep 3.<\/strong> Now delete this file from the temporary location.<\/p>\n<\/p>\n
\n\nSub Email_CurrentWorkBook()\n\n 'Do not forget to change the email ID\n 'before running this code\n \n Dim OlApp As Object\n Dim NewMail As Object\n Dim TempFilePath As String\n Dim FileExt As String\n Dim TempFileName As String\n Dim FileFullPath As String\n Dim MyWb As Workbook\n\n\n Set MyWb = ThisWorkbook\n \n With Application\n .ScreenUpdating = False\n .EnableEvents = False\n End With\n \n 'Save your workbook in your temp folder of your system\n 'below code gets the full path of the temporary folder\n 'in your system\n \n TempFilePath = Environ$(\"temp\") & \"\\\"\n 'Now get the extension of the file\n 'below line will return the extension\n 'of the file\n FileExt = \".\" & LCase(Right(MyWb.Name, Len(MyWb.Name) - InStrRev(MyWb.Name, \".\", , 1)))\n 'Now append a date and time stamp\n 'in your new file\n \n TempFileName = MyWb.Name & \"-\" & Format(Now, \"dd-mmm-yy h-mm-ss\")\n\n 'Complete path of the file where it is saved\n FileFullPath = TempFilePath & TempFileName & FileExt\n \n 'Now save your currect workbook at the above path\n MyWb.SaveCopyAs FileFullPath\n \n 'Now open a new mail\n \n Set OlApp = CreateObject(\"Outlook.Application\")\n Set NewMail = OlApp.CreateItem(0)\n \n On Error Resume Next\n With NewMail\n .To = \"info@learnexcelmacro.com\"\n .CC = \"info@learnexcelmacro.com\"\n .BCC = \"info@learnexcelmacro.com\"\n .Subject = \"Type your Subject here\"\n .Body = \"Type the Body of your mail\"\n .Attachments.Add FileFullPath '--- full path of the temp file where it is saved\n .Send 'or use .Display to show you the email before sending it.\n End With\n On Error GoTo 0\n \n 'Since mail has been sent with the attachment\n 'Now delete the temp file from the temp folder\n \n Kill FileFullPath\n \n 'set nothing to the objects created\n Set NewMail = Nothing\n Set OlApp = Nothing\n \n 'Now set the application properties back to true\n With Application\n .ScreenUpdating = True\n .EnableEvents = True\n End With\n \n \nEnd Sub\n\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"In previous Article, i had written how to Send Email from Excel Macro. In that article we had discussed how we can send any random file as an Attachment. Here in this article, you will learn how to send the ActiveWorkbook as an attachment. There could be two ways of sending the same workbook as […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[5205],"tags":[],"class_list":["post-12123","post","type-post","status-publish","format-standard","hentry","category-send-email"],"yoast_head":"\n
How to Send ActiveWorkbook as attachment in Email - Let's excel in Excel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n