I have my "MASTER.xlsm" Workbook opened. I run the code from "MASTER.xlsm".
I want to get values from my "MASTER.xlsm" to newly created Outlook email. I am not getting them there.
Is there something wrong with sequence in the code?
Sub EmailWithOutlook()
Dim oApp As Object
Dim oMail As Object
Dim WB As Workbook
Dim WBBW As Workbook
Dim FileName As String
Dim wSht As Worksheet
Dim shtName As String
Set WBBW = Workbooks("MASTER.xlsm")
WBBW.Worksheets("MAIN").Range("D134").Value = variableX
WBBW.Worksheets("MAIN").Range("D11").Value = variableY
WBBW.Worksheets("MAIN").Range("D13").Value = variableZ
Application.ScreenUpdating = False
' Make a copy of the active worksheet
' and save it to a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "My file"
On Error Resume Next
Kill "\" & FileName
On Error GoTo 0
WB.SaveAs FileName:=Environ$("temp") & "\" & FileName
'Create and show the Outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
.To = ""
'Uncomment the line below to hard code a subject
.Subject = "My subject | " & variableX & " | " & variableY
'Uncomment the lines below to hard code a body
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>Dear Sir/Madam, <br><br> please check this " & _
variableZ & "" & _
" and comment if needed.<br> Waiting for your reply ASAP. <br><br> Thank you!</BODY>" & .HTMLBody
.Attachments.Add WB.FullName
.Display
End With
'Delete the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False
'Restore screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub