+ Reply to Thread
Results 1 to 8 of 8

Error '424" Object Required on macro to send emails

  1. #1
    Registered User
    Join Date
    02-09-2018
    Location
    USA RALEIGH
    MS-Off Ver
    2013
    Posts
    8

    Error '424" Object Required on macro to send emails

    Hi All below is a piece of code that I am trying to get to work, the idea is that it send emails based on some cells value. I am getting the error on the lines marked with ***, any help will be appreciated.

    Thanks,



    Sub emailtest3()
    '
    ' emailtest3 Macro
    '

    '

    Dim r As Range
    Set r = Sheets("Pivot").Cells

    For i = 20 To 200



    Range("B1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("SO Number").ClearAllFilters
    *** ActiveSheet.PivotTables("PivotTable1").PivotFields("SO Number").CurrentPage = _
    *** OO2018.Range("AS" & i).Value

    ActiveWorkbook.EnvelopeVisible = True

    With r.Parent.MailEnvelope.Item
    .To = OO2018.Range("AX" & i).Value
    .CC = ""
    .BCC = ""
    .Subject = OO2018.Range("AW" & i).Value
    .Send
    End With

    Next i



    End Sub

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error '424" Object Required on macro to send emails

    OO2018.Range("AS" & i).Value
    What is the OO2018 supposed to be? If it is a sheet name then you need to use
    Please Login or Register  to view this content.
    Also note that the first two characters are Ohs and not zeroes.
    Last edited by JLGWhiz; 02-19-2018 at 02:40 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    02-09-2018
    Location
    USA RALEIGH
    MS-Off Ver
    2013
    Posts
    8

    Re: Error '424" Object Required on macro to send emails

    Thanks for your reply JKGWhiz, let me be a little more specific, below are some samples of what I want to accomplish:

    OO2018 and Pivot are in the same work book


    OO2018

    2018-02-19 14_04_46-Book1 - Excel.png

    Pivot

    2018-02-19 14_04_03-Book1 - Excel.png


    code for this example

    Sub emailtest4()
    '
    ' emailtest4 Macro
    '

    '


    Dim r As Range
    Set r = Sheets("pivot").Cells

    For i = 2 To 14


    Range("B1").Select
    ActiveSheet.PivotTables("PivotTable2").PivotFields("SO Number").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable2").PivotFields("SO Number").CurrentPage = _
    Sheets("OO2018").Range("C" & i).Value

    ActiveWorkbook.EnvelopeVisible = True

    With r.Parent.MailEnvelope.Item
    .To = OO2018.Range("h" & i).Value
    .CC = ""
    .BCC = ""
    .Subject = OO2018.Range("G" & i).Value
    .Send
    End With

    Next i




    End Sub


    now I am getting error 1004:
    "Unable to get PivotTable property of the worksheet class.


    this after change to the piece of code you gave me.


    Thanks again.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error '424" Object Required on macro to send emails

    You didn't make all the changes.

    Please Login or Register  to view this content.
    Which line of code is highlighted when you click debug?
    Also, I haven't used VBA to send mail in a long time, but I believe you need to create a send range , unless you are going to send the whole file as an attachment. Your setup does not contain a body for the email nor an attachment as near as I can tell.

    This link might help you more than I can.
    http://www.rondebruin.nl/win/section1.htm
    Ron Debruin has tons of VBA samples on this site for sending Excel data via email.
    Last edited by JLGWhiz; 02-19-2018 at 11:10 PM.

  5. #5
    Registered User
    Join Date
    02-09-2018
    Location
    USA RALEIGH
    MS-Off Ver
    2013
    Posts
    8

    Re: Error '424" Object Required on macro to send emails

    Thank you JLGWhiz, I actually find out that I am getting the error if I run the Macro while staying in a sheet different that in the Pivot Sheet, other than that your code help me to fix the main issue

    If there is anything that I can add to run the macro no matter what sheet I am in I will appreciate it, I tried doing

    sheets("pivot").Range("B1").Select

    and did not worked

    Thanks again.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error '424" Object Required on macro to send emails

    Here is an example of using a variable for your pivot sheet which would allow you to have another sheet as the active sheet while you run the macro.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-09-2018
    Location
    USA RALEIGH
    MS-Off Ver
    2013
    Posts
    8

    Re: Error '424" Object Required on macro to send emails

    perfect it worked like a charm.

    Thank you so much.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Error '424" Object Required on macro to send emails

    Quote Originally Posted by vromero2018 View Post
    perfect it worked like a charm.

    Thank you so much.
    You're welcome,
    regards, JLG

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Script not copying data from "Emails" sheet to "New Sheet" - Run time error: Object
    By methuselah90 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2014, 03:22 PM
  2. [SOLVED] Macro generates the following error: "run-time error 424 object required"
    By Metrazal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2014, 06:31 PM
  3. Set Variable = File Path generates "Object Required" Error
    By Brian48072 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2013, 11:42 AM
  4. "Object required" error with VBA loop rows deleting
    By JKWIN in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2012, 09:31 AM
  5. [SOLVED] "Object required" error in combo box/macro combination
    By chemeng1T3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-09-2012, 10:32 AM
  6. [SOLVED] Excel 2007 : Help to Solve Run-time Error 424 "Object Required"
    By D.S.Rama Rao in forum Excel General
    Replies: 6
    Last Post: 03-05-2012, 03:24 PM
  7. [SOLVED] "Microsoft Visual Basic runtime error '424' object required".
    By SharonG. in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-04-2006, 08:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1