Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS to NOT open PDF file 2

Status
Not open for further replies.

supportsvc

Technical User
Jan 24, 2018
249
US
For some reason the PDF file opens and I do not want it to open.
Just send the email

Code:
Set objcExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\ReportResults\BacklogEmail.xlsm'!Module!.sendBacklogEmail"
objExcel.DisplayAlerts = False
ojbExcel.Application.Quit
Set ojbExcel = Nothing

This code does create the worksheet as a PDF and does send the email
However it opens the PDF, I don't want it to do that.
Not sure how to edit so it will not open the PDF when running this script.

NOTE: this script will be used in Windows Task Scheduler
 
Hi,

“This code does create the worksheet as a PDF and does send the email”

Well, what is “this code?”

Please post sendBacklogEmail.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I suspect it's
Code:
OpenAfterPublish:=True
?

Code:
Sub sendBacklogEmail()
ChDir "C:\Reports\Custom\Backlog.xslm"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename"C:\Reports\Custom\ReportResults\Backlog-3Days.pdf", OpenAfterPublish:=True

Dim OutlookApp As Object
Dim OutlookMailItem As Object
Dim myAttachments As Object

Set OutlookApp = CreateObject("Outlook.application")
Set OutlookMailItem = OutlookApp.CreateItem(0)
Set myAttachments = OutlookMailItem.Attachments

With OutlookMailItem
.To = "your@email.com"
.Subject = "Backlog 3 Days Report"
.Body = "Good morning, here is the daily Backlog 3 Days Report."
myAttachments.Add "C:\Reports\Custom\ReportResults\Backlog-3Days.pdf"
.send
End With

Set OutlookMailItem = Nothing
Set OutlookApp = Nothing

End Sub
 
The key here is:

[tt]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename"C:\Reports\Custom\ReportResults\Backlog-3Days.pdf", OpenAfterPublish:=True
[/tt]
Change it to

[tt]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename"C:\Reports\Custom\ReportResults\Backlog-3Days.pdf", OpenAfterPublish:=[red]False[/red][/tt]
 
And - for future reference - Office VBA questions are best asked in forum707


---- Andy

There is a great need for a sarcasm font.
 
Thanks, that's what I was thinking.

Thanks Andy, missed that forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top