Runtime Error (91)

dermitdenaces

New Member
Joined
Apr 5, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
When asking about a runtime error, always indicate which line of code is highlighted when the error occurs. I don't see anything obvious but it will be clearer if we know it's a specific line of code.

What module contains this code?
What sheet is active when you run this code?
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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