VBA - Sending mail and closing workbook with out saving - Macro Tweek Required

DebugGalpin

Board Regular
Joined
Jun 29, 2011
Messages
175
Hi guys,

I have the below macro I am using to pdf a sheet and send in an email. The problem is when I close the new workbook I can't seem to get the option to save not to appear even with Application.DisplayAlerts =False.... Any idea would be greatly appreciated

Cheers
DAVE


Option Explicit

Sub EmailPDF()
Application.DisplayAlerts = False
Dim MyFileName, FilePath, Folder, s, t, FileName, Address, Subject, Body As String

FilePath = Range("FilePath")
Folder = Range("Folder")
FileName = Range("FileName")
Address = Range("Email")
Subject = Range("Subject")
Body = Range("Body")
s = FilePath & "\" & Folder
t = FilePath & "\" & Folder & "\" & FileName
If Len(Dir(s, vbDirectory)) = 0 Then
MkDir (s)
End If

Application.DisplayAlerts = False
ActiveWorkbook.Worksheets("Template CDS").Copy
ActiveWorkbook.ExportAsFixedFormat xlTypePDF, t & ".pdf"

Dim olApp As Outlook.Application 'MUST RERENCE MICROSOFT OUTLOOK 9/10/11/12 OBJECT LIBRARY.
Dim olMail As MailItem

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail
.To = Address
.CC = ""
.Subject = Subject
.Body = Body
.Attachments.Add t & ".pdf"
.Display
End With

Set olMail = Nothing
Set olApp = Nothing

Application.DisplayAlerts = False
ActiveWorkbook.Close False


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Use
ActiveWorkbook.Close
instead of
ActiveWorkbook.Close False
False says Excel that you do not want to save any change. The omitted (True/False) parameter of this method imparts to Excel to check a state of the active book (changed or not).
 
Upvote 0
Maybe, your book never changes during a work with it include that macro.
Try such a variant of end
Code:
    Set olMail = Nothing
    Set olApp = Nothing
    
    Application.DisplayAlerts = False
    ActiveWorkbook.Saved = False 'To set a file is changed
    ActiveWorkbook.Close
    End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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