My PDFs dont save properly because of my code, don't know how to fix it

Erik968

New Member
Joined
Feb 8, 2019
Messages
12
This code is supposed to save the file as PDF to my pc and after that mail the XLSM and PDF file as attachments in an automated mail... but my pdf's dont get saved properly because my code is wrong and I just dont know how to fix it, does anyone know how I can fix it?

Code:
Sub saveandsend()


Dim Path As String
Dim filename As String
Path = "C:\Users\Erik Stoeken\Documents\van Wijk\Excel test\"
filename = Range("P39")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsm"


' SendEmail Macro
'


Dim outlookapp As Object
Dim OutlookMail As Object
Set outlookapp = CreateObject("Outlook.Application")
Set OutlookMail = outlookapp.CreateItem(0)
On Error Resume Next
With OutlookMail
    .To = "erikstoeken@gmail.com"
    .CC = ""
    .BCC = ""
    .Subject = Range("X22")
    .Body = "Bon zit in de bijlage."
    .Attachments.Add Application.ActiveWorkbook.FullName
    .Attachments.Add (Path & filename & ".PDF")
    .Display
End With
Set OutlookMail = Nothing
Set outlookapp = Nothing




End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Eric Golf

Active Member
Joined
Dec 19, 2007
Messages
324
Re: My PDF's dont save properly because of my code, dont know how to fix it.. (read description)

Hi,

I don't see anywhere in your code that you are saving a file as type PDF?

Also it best to avoid using keywords as variable names e.g. "filename:=Path & filename & ".xlsm""

Hope this helps,

Eric
 

Erik968

New Member
Joined
Feb 8, 2019
Messages
12
Re: My PDF's dont save properly because of my code, dont know how to fix it.. (read description)

This is basically the biggest problem im having, I dont know much about VBA and was just watching some tutorials and now im stuck with this, all I know is that it is definitely saving files to my pc but they arent files what I can open... I just dont know what I need to add to get PDFs...

thanks for the reply.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,129,593
Messages
5,637,294
Members
416,963
Latest member
zazama

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