Share via

VBA compile error: variable not defined in Excel after Office updates to v2212. What's going on?

Anonymous
2023-01-14T17:51:07+00:00

I have a number of users, myself included, who are getting the variable not defined error when opening files with macros that have worked for years. The common element in all these cases is that Office had updated to v2212. Users with v2211 work fine. Excel often becomes unstable after OKing out of the errors. In addition, I've had a number of people with the same problem respond to a discussion forum post I created a couple days ago. Again, the common element is v2212. If someone could please elevate this situation or provide some additional insight, that would be great. It seems to be affecting a lot of users with VBA code in their files.

Microsoft 365 and Office | Excel | Other | Windows

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

26 answers

Sort by: Most helpful
  1. Anonymous
    2023-02-02T04:21:25+00:00

    @AlexC84,

    Sorry I didn't respond sooner but I wanted to test out the new update (2301) before responding. I've only tested it on one computer so far but I was able to test a bunch of files that were throwing the error on 2212. They loaded and ran without any errors after the 2301 update was installed so it appears to have fixed the problem. If you find out otherwise, please post back here.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-01-20T21:12:15+00:00

    @Tony,

    Thanks for all the information. At this point, I don't think there's a reliable solution. I've done the VBA cleaning that I discussed in previous posts and had some success. I've distributed updated files to about 30 users so far and it has worked for all but four. However, I've had two users contact me today where it worked initially but stopped working after a couple days.

    Rolling back to the 2211 update is the only realistic solution. I've had a lot of success having users check the "Disable Trusted Documents" checkbox in Excel's Trust Center Settngs, which forces the user to click the Eanble Content button each time. Anything that will allow the file to open completely before VBA code starts running. That seems to work unless the user has the Excel vba window open, then they get the error. I can't really explain why that would be the case and I'm not sure if that would work for your files.

    It's getting really annoying as I have hundreds of users and every day more of them get the Office update and have the problem. I just wish Microsoft would pause the roll out. I'm tired of spending my days trying to find workarounds for their bad release. I hope someone in Redmond is at least paying attention.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2023-01-16T10:31:11+00:00

    We have a similar issue with our macro enabled workbooks (significant VBA projects including userforms).

    We use M365 for Business, and we have been updated to Excel Build v2212. When opening the affected workbook via teams/sharepoint or syncing it to the local machine with the OneDrive sync client we get compile errors; i.e. we get VBA errors when the file is trusted.

    If we download the workbook from Teams/Sharepoint then the file is 'foreign' and marked with the 'Mark of the Web' (i.e. not trusted), subsequently when opening the file we are required to unblock macros - then the file can be opened with no compile errors and everything works fine

    We have only experienced this since Excel v2212 (Jan 4 Build 15928.20198, and Jan 10 Build 15928.20216)

    Also: Recently Excel 2212 Build 15928.20216 has been rolled out and is - Microsoft Community

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2023-01-15T04:04:33+00:00

    Thanks OssieMac, I initially thought there might be an issue with the references, but I've checked them and they're all intact and pointing to the correct file. I have fourteen users of two different programs reporting the problem so far and I expect to get a lot more. I get a few every day since the Office update has been rolling out. I've reliably reproduced the problem on multiple computers. I'd love to send you a file so you can see for yourself. If you'd like, you can download a copy of the affected file by going to my website at www.djicomputer.com and clicking on the Handicap Manager link and downloading the zip file version of the program. Unblock the macros in the included Excel file and open the Excel file. When you get the security warning, click the Enable Content button, then click Yes when prompted to Trust the file. The file will open without error. Then close the file and re-open it and you should get the "Variable not defined" error as long as you're not prompted again to Enable Content. I'm not sure if these files run on the Mac version of Excel so it would be best to test it on a Windows machine if possible.

    Myself and all my users have been using these files for months/years with no issues and they're getting the errors since the update. Rolling back the updates solves the problem so there has to be something related to the update. I posted on another forum (see link below) and a few other people have chimed in with the same issue. I hate to take up your time but I'm desperate for an answer. If you could look into it further or somehow escalate my concern or point to some way that I can escalate it. I've contacted tech support and they just want to roll back the update to fix the problem. I've cleaned all my code by exporting the modules, creating new ones and copying the code text back in thinking that might solve it but no such luck. I have hundreds of users and I expect to get more complaints every day as the update rolls out and they start using their files. Thanks in advance for any assistance you can provide.

    Link to other forum post: Variable not defined errors with Excel update 2212 dated 04 January - Microsoft Community

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  5. OssieMac 48,001 Reputation points Volunteer Moderator
    2023-01-14T20:31:01+00:00

    I have run some tests but so far, I have not been able to emulate the problem.

    Are you using Option Explicit as the first line in the module and then declaring the variables with the Dim statement? If not, try inserting Option Explicit at the start of the module and then declare the variables. After declaring the variables, Select menu item Debug -> Compile and it will identify any variables that have not been declared. More information on declaring variables at the following Microsoft link.

    https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/declaring-variables

    Also, I am wondering if it is specific types of variables so could you please post some code and tell us which line is producing the error.

    Was this answer helpful?

    0 comments No comments