Macro not attaching Current workbook

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have the following code, which works fine, except that the active workbook is not being attached to the outlook email created


Kindly amend my code



Code:
 Sub Email_Report()
   ThisWorkbook.Activate                           'start in THIS workbook
ztext = [bodytext]                              'read in text from named cell
Zsubject = [subjectText]

Sheets("Summary Inventory").Select


    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next

 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    
      
        With OutMail
            .To = Range("T1:T1").Value
            
            .CC = Join(Application.Transpose(Range("T2:T5").Value), ";")
            
            .BCC = ""
            .Subject = Zsubject
           .Body = ztext
          

            
            .Attachments.Add Destwb.FullName
            '
            .Display   'Use .send to send automatically or  .Display to check email before sending
        End With
        

  On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing


    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
   
    
End Sub
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
But how is defined (and what is the content of):
Code:
Destwb.FullName
It's probably not (or is empty).
You can see/check it by adding:
Code:
           .Body = ztext
          

            msgbox "here shall be attachment file path and name: >" & Destwb.FullName & "<"
            .Attachments.Add Destwb.FullName

So add before your code something like:
Code:
dim Destwb as workbook
set Destwb = thisworkbook

and after your code:
Code:
set Destwb = nothing 'to clear memory
 
Last edited:
Upvote 0
thanks for your input. Code now attaches workbook
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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