File format and send via outlook

Scrappy666

Board Regular
Joined
Jul 6, 2012
Messages
215
Hi Everyone,

I've came across a small problem whilst writing my latest bit of VBA..

I have the below code which select the file format when sending a document through Outlook, however i want to send this document as a PDF.

I've tried amending the file extension to .pdf to no avail...
It does send as a PDF but it won't open the document, the error message is saying it's in the wrong file format :confused:


Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select


If anyone knows how I can amend the above to save as a PDF it would be greatly appriciated!!
The original code came from Microsoft's website:

Using VBA in Excel to Send Workbooks and Ranges Through E-Mail with Outlook (Part 1 of 2)

The exact bit i've used is under the heading 'Mailing Single Sheets as Attachments'

Thanks in advance,
Dan
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
Range("myRange").ExportAsFixedFormat xlTypePDF, "myPath here"
 

Scrappy666

Board Regular
Joined
Jul 6, 2012
Messages
215
Sorry i'm not overly technical with VB!

Would that replace everything above?
And the file isn't being exported and saved, it's being sent by email in a further bit of code below, would this still work?
 

Forum statistics

Threads
1,137,060
Messages
5,679,376
Members
419,824
Latest member
Mercy kiara

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
Top