Excel for Mac - Runtime Error '91': Object variable or With block variable not set

Anonymous
2023-03-01T16:00:42+00:00

Hello,

When attempting to run an Excel macro I receive the error message Runtime Error '91': Object variable or With block variable not set.

The macro is not created by me but the source is trustworthy and I know that it works on PC. If shared via OneDrive it works a PC but not on the Mac. How can I solve this?

Thanks!

Microsoft 365 and Office | Excel | For business | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Andreas Killer 144K Reputation points Volunteer Moderator
    2023-03-02T04:49:06+00:00

    I would assume this is the case then, that the code is not compatible with Mac. Are there any guidelines on how to create a code compatible with both Mac and PC?

    Hi Linda,

    No, the problem is generally simple:

    Sometimes you need to do special tasks which are not possible using VBA and/or what Excel provides. In Windows there are many external DLL files, which are libraries that export functions, inside the system folder which we can access / use to do this tasks.

    A Mac does not have this structure and does not provide it because of its security concept.

    Therefore, many things are not possible on a Mac.

    Andreas.

    5 people found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Andreas Killer 144K Reputation points Volunteer Moderator
    2023-03-01T16:04:41+00:00

    Depends on the VBA code... but in most cases the code is not compatible with a Mac and therefore the file is not compatible with your Mac.

    Andreas.

    0 comments No comments
  2. Anonymous
    2023-03-01T16:09:44+00:00

    Hi Linda,

    Greetings! Thank you for posting to Microsoft Community.

    There are two steps to creating an object variable. First you must declare the object variable. Then you must assign a valid reference to the object variable using the Set statement.

    Object variable not set (Error 91) | Microsoft Learn

    Share your code will help to check your issue.

    Best Regards,

    Snow Lu

    0 comments No comments
  3. Anonymous
    2023-03-01T16:33:14+00:00

    Hello Andreas and Snow,

    Thank you for the quick replies.

    I would assume this is the case then, that the code is not compatible with Mac. Are there any guidelines on how to create a code compatible with both Mac and PC?

    It would be great to be able to let the supplier of the code know this so that they instead can provide a file with a code that is compatible also for Mac.

    • Linda
    0 comments No comments