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!
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