4

I am supplying the correct password

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("H:\M\X\C.xls", 0, , , "password")

'any of these lines cause the error mentioned

Set vbcomp = objWorkbook.VBProject.VBComponents(modname)
objWorkbook.VBProject.VBComponents.Remove vbcomp
objWorkbook.VBProject.VBComponents.Import modpath & modtest

Any ideas what the problem might be? Tools-Macro-Security is set to allow VB project access

Helen
  • 87,344
  • 17
  • 243
  • 314
adolf garlic
  • 3,034
  • 7
  • 39
  • 54

3 Answers3

5

The VBA project itself is protected by a password which is different then the worksheet password. Open the VBA IDE - select Tools-VBA Project Properties and look at the Protection Tab.

Not sure how or if you can remove the VBA Project password using code.

DJ.
  • 16,045
  • 3
  • 42
  • 46
  • Correct. It does not appear to be possible to removed the password on the VBA project, unless you use a hideous 'sendkeys' type workaround. – adolf garlic Apr 15 '09 at 07:14
  • There's another [StackOverflow](https://stackoverflow.com/questions/16174469/unprotect-vbproject-from-vb-code) answer on how to do it with code, but it's not easy. – Slogmeister Extraordinaire Jul 08 '20 at 14:41
0

This may sound extreme, however I managed to get around this by downloading Windows Installer Clean up Utility (look for msicuu2.exe in Google) and removed office 2003. I then reinstalled office 2003 and my problem had disappeared. Hope it solves your problem too. Alex

Roman C
  • 49,761
  • 33
  • 66
  • 176
Alex
  • 1
0

I found that you will sometimes get this error when you've saved a new module to the project model.

When I've had this error pop up it has sometimes gone away just by saving the new module to the project before continuing. Other times saving and then compacting didn't help - only closing and re-opening the database allowed me to run the well-tested function (in a different, previously saved module) which uses the project model.

Pretty silly but I've wasted time on more than one occasion trying to troubleshoot what I initially assumed was a Trust Center issue so hopefully this is helpful to someone else.

Marcucciboy2
  • 3,156
  • 3
  • 20
  • 38