dermitdenaces
New Member
- Joined
- Apr 5, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hi,
i am having trouble with my code. Im getting a runtime error 91. Could you tell me whats wrong? Thanks.
i am having trouble with my code. Im getting a runtime error 91. Could you tell me whats wrong? Thanks.
VBA Code:
Sub Send_Mail_Esk()
Dim emailApplication As Object
Dim emailItem As Object
Dim strPath As String
Dim lngPos As Long
strPath = ActiveWorkbook.FullName
lngPos = InStrRev(strPath, ".")
strPath = VBA.Left(strPath, lngPos) & "pdf"
Dim activerow As Long
activerow = ActiveCell.Row
ActiveSheet.Unprotect ""
'Copies Cells for Printing to bottom of cell
ActiveSheet.Range(("B3:N8") & ",B" & activerow & ":N" & activerow).Copy Sheets("Model").Range("B212:M221")
ActiveSheet.PageSetup.PrintArea = "B212:N221"
ActiveSheet.PageSetup.Orientation = 2
ActiveSheet.PageSetup.Zoom = False
ActiveSheet.PageSetup.FitToPagesWide = 1
ActiveSheet.PageSetup.FitToPagesTall = 1
ActiveSheet.ExportAsFixedFormat xlTypePDF, strPath
Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)
emailItem.To = Sheets("Model").Range("AD" & activerow).Value
emailItem.Subject = Sheets("Model").Range("AE" & activerow).Value
emailItem.HTMLBody = Sheets("Model").Range("AF" & activerow).Value
emailItem.Attachments.Add strPath
emailItem.Display
Set emailItem = Nothing
Set emailApplication = Nothing
'Deletes All Copied Cells and Pictures from previous copy
Sheets("Model").Range("B212:N221").Delete
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not Application.Intersect(pic.TopLeftCell, Range("B208:N221")) Is Nothing Then
pic.Delete
End If
Next pic
ActiveSheet.Protect ""
' Delete the PDF file (not nesecarry) keep most recent updated send file
End Sub