0

Using VB for Excel in Excel 2003, I have no problems executing code with some non-declared variables:

numberOfBooks = 0

However, if I try to execute the same code in Excel 2007, I get a "Can't find project or library" error message.

I looked at Tools > Options and I don't have checked "Require Variable declaration". In Excel 2003 I did not use Option Explicit

What am I doing wrong? Thank you very much.

user56380
  • 93
  • 4
  • 9

3 Answers3

2

I have seen this advice (check references) a number of times and it makes sense!

However, when the fault: "can't find project or library" develops, you are in run mode and I cannot get out of it? Waht am I missing?

maarten
  • 21
  • 2
0

I'd definitely second Daniel Cook's suggestion of checking your references list; that may be it. However I've come across some situations over the last couple of months where that error will occur in an Excel 2007 even if there is nothing wrong with the references. In part it seems to relate to the security updates that were released in August 12 ( http://technet.microsoft.com/en-us/security/bulletin/ms12-aug ). It caused some breakage in the mscomctl.ocx. The problem and (one) resolution (basically, re-registering the .ocx) is discussed in this IBM link which relates to an Excel add-in for an OLAP product called TM1: http://www-01.ibm.com/support/docview.wss?uid=swg21608271. (The error messages aren't the same as the ones that you've been getting, but I DID get your error messages on another add-in that I wrote which were not missing any references, and it turned out to be the same problem.)

The other thing I'd suggest doing is a purge of your .exd files as discussed here: http://support.microsoft.com/kb/290537 I've also found that those can cause bogus library errors, particularly after a version upgrade.

As for anything else you're doing wrong, well, personally I tend to skin anyone who works for me without using Option Explicit. 8^>

Alan K
  • 1,957
  • 3
  • 19
  • 30
  • Hi, it worked! Finally I checked the References (what Daniel cook suggested) and found that "Microsoft Calendar Control 11.0" was missing. I copied MSCAL.OCX y MSCAL.HLP files from one PC with Excel 2003 into "C:\WINDOWS\SysWOW64" folder (my Excel 2007 is in a 64-bit PC) and registered the control with "regsvr32.exe mscal.ocx". Thank you very much! :-) – user56380 Oct 29 '12 at 14:34
0

One of our companie's excel-macros (which ran quite frequently without any issues so far) all of a sudden came up with exactly the same error. We didn't touch the code for like forever. And I honestly have still no idea what actually caused this error. Mistery Microsoft maybe? Anyways.. I finally were able to fix the bug.

Even though "Require Variable declaration" was disabled and Option Exlicit was not set in my case, declaring the variable first did the trick for me:

Dim numberOfBooks As Integer: numberOfBooks = 0

I hope this saves some headaches.

Alan
  • 411
  • 6
  • 18