hi ,
can anyone help with the below code ?
the code is supposed to export 2 worksheets in the same workbook to separate pdfs ,
saved to an external drive, with creating a folder with the name of cell F1 .
then one of the pdf files added to a new outlook message .
but all i get is a "runtime error code 1004"
and when i debug it highlights this part of the code
any ideas ?
will be much appreciated if anyone can help
thanks in advance
dave
can anyone help with the below code ?
the code is supposed to export 2 worksheets in the same workbook to separate pdfs ,
saved to an external drive, with creating a folder with the name of cell F1 .
then one of the pdf files added to a new outlook message .
but all i get is a "runtime error code 1004"
VBA Code:
' Generate a PDF file and attach to new email
Sub PublishProjectPDFs()
Const olMailItem = 0
Dim MyMailItem As Object ' MailItem
Dim NewRecipient As Object ' Recipient
Dim PDFFileName As String
Dim OutlookApp As Object
Dim Path As String
Set OutlookApp = CreateObject("Outlook.Application")
ThisWorkbook.Sheets(Array("COSTING", "QUOTATION")).Select
Path = "Z:\quotations\" & Worksheets("COSTING").Range("F1") & "\"
PDFFileName = Worksheets("COSTING").Range("A1")
Worksheets("COSTING").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Path & "COSTING", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Worksheets("QUOTATION").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Path & "QUOTATION", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set MyMailItem = OutlookApp.CreateItem(olMailItem)
MyMailItem.display
Set NewRecipient = MyMailItem.Recipients.Add("Recipient Name <email@address.com>")
NewRecipient.Type = olTo
NewRecipient.Resolve
MyMailItem.Subject = "Your subject here"
MyMailItem.body = "Message for email body here"
MyMailItem.Attachments.Add Path & "QUOTATION"
End Sub
and when i debug it highlights this part of the code
VBA Code:
Worksheets("COSTING").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Path & "COSTING", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
any ideas ?
will be much appreciated if anyone can help
thanks in advance
dave