Print to PDF and email from Excel Problem

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
I keep getting an error when trying to run this code on the line highlighted in red. The error is "Run-time error '438': Object doesn't support this property or method".

This code creates the pdf file just fine, but hangs up when trying to get the file, in fact Outlook never starts. I tried adding a time delay but that only pauses then errors out. I am so close but can't seem to get over the hurdle to the finish line......and I am out of ideas! Help please!

Code:
'====================================================
'MACROS TO print p.o. to pdf file
'====================================================
Sub PrinttoPDF()
 
    Application.ScreenUpdating = False
    ActiveSheet.DisplayPageBreaks = False
 
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "CutePDF Writer on CPW2:", Collate:=True
    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + 2
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
 
    filename = "M:\POs All locations\" & ActiveSheet.Range("PrintName").Value & ".pdf"
 
    SendKeys filename & "{Enter}", False
    Set ws = ActiveSheet
    Application.ScreenUpdating = True
EmailFile
End Sub
 
 
'====================================================
'MACROS TO email pdf file
'====================================================
Sub EmailFle()
 
    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + 5
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime
    Application.DisplayAlerts = False
 
    Set obOutApp = CreateObject("Outlook.Application")
    Set obOutMail = obOutApp.CreateItem(0)
 
    With obOutMail
        .To = "this is where I have the email address"
        .Subject = "Test Email"
        .Body = "See Attached Purchase Order and Matrix"
       [COLOR=red].Attachment.Add ("M:\POs All locations\" & ActiveSheet.Range("PrintName").Value & ".pdf")[/COLOR]
        .Display
    End With
 
    Application.DisplayAlerts = True
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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