+ Reply to Thread
Results 1 to 6 of 6

"Object required" error upon "Exit Function" statement

  1. #1
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    "Object required" error upon "Exit Function" statement

    I have an OpenProject function in Excel VBA that returns an Object. The purpose is to open a Microsoft Project file and return the Project as an object. The code is being written to be able to run in either Excel or Project. The OpenProject function opens the project correctly and correctly assigns it to the return value for the function. When I debug after the project is opened, I am able to use commands in the Immediate window to get the name of the project and number of tasks, so I know the object is valid.

    However, when the Exit Function statement is executed I get an "Object required" error. I have seen this error occur on various statements but never on an Exit Function statement when the return object is valid. What could possibly cause this on Exit Function?

    I have attached a file that has been skinnied down to the minimal code to reproduce the error.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: "Object required" error upon "Exit Function" statement

    I'm surprised that compiles; the invocation of OpenProject doesn't agree with OpenProject's signature.

    Please Login or Register  to view this content.
    Fix that and it works:

    Please Login or Register  to view this content.
    Last edited by shg; 12-24-2018 at 03:34 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: "Object required" error upon "Exit Function" statement

    Or early-bound,

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,251

    Re: "Object required" error upon "Exit Function" statement

    1. What if 'MSProject' is not installed ?

    Maybe:
    Please Login or Register  to view this content.
    2. ... in function:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: "Object required" error upon "Exit Function" statement

    Please Login or Register  to view this content.
    I believe it is necessary, otherwise the Else clause will execute.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,779

    Re: "Object required" error upon "Exit Function" statement

    Quote Originally Posted by shg View Post
    I'm surprised that compiles; the invocation of OpenProject doesn't agree with OpenProject's signature.
    Thanks for finding that! I am surprised it compiles, too. I am also surprised that it fails on the Exit Function statement, of all places. But your fix worked.

    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.
    I believe it is necessary, otherwise the Else clause will execute.
    On review I think that final Exit Function is indeed unnecessary since it is the last line of code in the function. I think it must be an artifact leftover from when it was followed by some other code.

+ 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. [SOLVED] "ActiveWorkbook.Path" fails - triggers "Compile Error Object required"
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-15-2018, 02:58 PM
  2. Replies: 35
    Last Post: 01-13-2016, 02:16 AM
  3. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  4. "The "sheets" method from the "_Global" object have failed."
    By mankit87 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2011, 08:53 AM
  5. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  6. Replies: 3
    Last Post: 12-14-2006, 01:36 PM
  7. What is Error "Method "Paste" of object "_Worksheet" failed?
    By vat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2006, 04:10 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