03856me
Active Member
- Joined
- Apr 4, 2008
- Messages
- 297
I have the following code written, the printing to a pdf file was working perfectly, then I added the email code. It works the first time but then I am getting the following error on the row underlined in purple. If I save and close the file, then go back in, it works again the 1st time only.
Run-time error '2147024894 (80070002)':
Cannot find this file. Verify the path and file name are correct
=================================================
Sub PrinttoPDF()
If Range("EffectiveDate") > "" Then
Answer = MsgBox("Do you want to complete p.o.? Yes will 1)post, 2)reset p.o.#, 3)print to pdf file", _
vbYesNo, "Complete")
If Answer = vbNo Then Exit Sub
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
'=== EMAIL SECTION OF CODE ===
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "See Attached NEW Purchase Order and Matrix"
nameList = Sheets("Template").Range("emailLinda").Value
Email_Send_To = nameList
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Attach your MATRIX then SEND to Linda!"
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(o)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.CC = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.Attachments.Add ("m:\POs All locations\" & ActiveSheet.Range("PrintName").Value & ".pdf")
.Display
'.send
End With
' MsgBox "E-mail successfully sent"
Application.DisplayAlerts = False
'=== END OF EMAIL CODE ===
End If
End Sub
=========================================
thanks for your help
Run-time error '2147024894 (80070002)':
Cannot find this file. Verify the path and file name are correct
=================================================
Sub PrinttoPDF()
If Range("EffectiveDate") > "" Then
Answer = MsgBox("Do you want to complete p.o.? Yes will 1)post, 2)reset p.o.#, 3)print to pdf file", _
vbYesNo, "Complete")
If Answer = vbNo Then Exit Sub
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
'=== EMAIL SECTION OF CODE ===
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "See Attached NEW Purchase Order and Matrix"
nameList = Sheets("Template").Range("emailLinda").Value
Email_Send_To = nameList
Email_Cc = ""
Email_Bcc = ""
Email_Body = "Attach your MATRIX then SEND to Linda!"
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(o)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.CC = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.Attachments.Add ("m:\POs All locations\" & ActiveSheet.Range("PrintName").Value & ".pdf")
.Display
'.send
End With
' MsgBox "E-mail successfully sent"
Application.DisplayAlerts = False
'=== END OF EMAIL CODE ===
End If
End Sub
=========================================
thanks for your help