# Broken VBAProject Reference



## joethall (Jul 16, 2008)

If I open an brand new Excel 2007 spreadsheet, open Visual Basic, left-click Tools, left-click References, scroll down to Microsoft WinHTTP Services, version 5.1 and select it.

On my system the location given at the bottom of the window is:
C:\Users\JoeAdmin\Documents\%SystemRoot%\system32\winhttp.dll

If I check the box for this entry and hit OK it will fail with "Error in loading DLL".

I can find no way to correct the location to:
C:\Windows\system32\winhttp.dll
This is where a fresh version of winhttp.dll exists.

I have searched hign and low for any material on this issue and have found none.

Can anyone tell me how to:
- Edit this location
- Remove this entry totally so that I can reinstall it from scratch
- Anything else that might solve this problem

Thanks!


----------



## David M58 (May 20, 2008)

You may be able to update the reference by running this line of code:


```
ActiveWorkbook.VBProject.References.AddFromFile "C:\Windows\System32\winhttp.dll"
```


----------



## joethall (Jul 16, 2008)

Well, that worked to some extent. The entry "Microsoft WinHTTP Services, Version 5.1" is now checked (and that didn't work before) but when it is selected it has the wrong Location.


----------



## David M58 (May 20, 2008)

I think that the location displayed in the References dialog may be inaccurate. %SystemRoot% normally refers to C:\Windows, so the entry:
C:\Users\JoeAdmin\Documents\%SystemRoot%\system32\winhttp.dll
does not look right to me. There is definitely a glitch somewhere.


----------



## joethall (Jul 16, 2008)

Yes, I very much agree that the location of C:\Users\JoeAdmin\Documents\%SystemRoot%\system32\winhttp.dll
is bogus. However, I have not been able to find a way to either modify the location or even to remove the entry all together.

In VBA there appears to be the method ActiveWorkbook.VBProject.References.Remove but I have yet to come up with the proper way to reference the WinHTTP reference.


----------



## David M58 (May 20, 2008)

I understand, Joe.

Once the AddFromFile is done, if I run:

Debug.Print ActiveWorkbook.VBProject.References("WinHttp").Description

it returns:

Microsoft WinHTTP Services, version 5.1

If I run:

Debug.Print ActiveWorkbook.VBProject.References("WinHttp").FullPath

it returns:

%SystemRoot%\system32\winhttp.dll

If anyone else has some insight into this, that would be great.


----------



## Glaswegian (Sep 16, 2005)

%SystemRoot% is certainly the correct location. Try going to the file in the Documents folder and rename it to winhttp.dll.old - then try in the VB Editor again.

If the version in your system32 folder is not found (although it is physically there) you may need to re-register the file.

Go to *Start*->*Run* and copy and paste the following into the box, 

*regsvr32 winhttp.dll*

then click OK. Now reboot your system.

Let us know if that works.


----------



## joethall (Jul 16, 2008)

Guys, both of you, thanks! However, things did not work out all that well.

I must not have something configured right because the suggested Debug.Print statements get "Subscript out of range". I'm guessing that this is the References("WinHttp"), but I don't know how to fix it.

Can you tell me where to find the object model documentation that shows that, for example, Description is a value of References? I've search all over and can't seem to find anything like that.

I did find the file in C:\Users\JoeAdmin\Documents\System32\winhttp.dll and I renamed it to winhttp.dll_old. However, this did not cause any change in any of the behaviors.

I ran *regsrv32 winhttp.dll* and I get "The module "winhttp.dll" was loaded but the call to DllRegisterServer failed with error code 0x80070005". I've search around for this error code and found nothing useful to this particular problem.

Finally, the statement *ActiveWorkbook.VBProject.References.AddFromFile "C:\Windows\System32\winhttp.dll"* causes the checkbox to be set and the entry to show up at the bottom of the list of already checked boxes. HOwever, the Location is still incorrect.

I did save the spreadsheet and when it was reopened the entry was still at the bottom of the checked list but with the wrong location.

Please keep the thoughts coming as I have the feeling that we are slowly but surely sneaking up on a solution!

Thanks!


----------



## joethall (Jul 16, 2008)

One other thing, *regsvr32 /u winhttp.dll* gets the same 0x80070005 error.


----------



## Glaswegian (Sep 16, 2005)

Hi Joe

It does appear that this is a problem unique to the combination of Vista and XL2007. I have found others who have reported that Vista/Excel seems to append the correct path to the dll on to the Excel file location. The indications are that this is indeed some kind of invalid registration of the dll file. Let's try re-registering the dll using the full path this time

As before, click Start > Run and copy/paste the following into the Run box

*regsvr32.exe "c:\windows\system32\winhttp.dll" *

Click OK - if all goes well you should receive a message something like

*"DllRegisterServer in c:\windows\system32\winhttp.dll" *

Then try adding the Reference again and see if the path is now correct.


----------



## joethall (Jul 16, 2008)

Trying *regsvr32.exe "c:\windows\system32\winhttp.dll" * gets me that same 0x80070005 error. "The module c:\windows\system32\winhttp.dll was loaded but the call to DllRegisterServer failed with error code 0x80070005."

I've discovered that ActiveWorkbook.VBProject.References.Item(I).FullPath is shown to be: *%SystemRoot%\system32\winhttp.dll* and I note that this, at least in and of itself, seems right.

Just to be complete and in the hopes it triggers someone, here's the rest of the ActiveWorkbook.VBProject.References.Item information:

Description: Microsoft WinHTTP Services, version 5.1
FullPath: %SystemRoot%\system32\winhttp.dll
Builtin: False
Major: 5
IsBroken: False
Guid: {662901FC-6951-4854-9EB2-D9A2570F2B2E}
Collection.Count: 6
Collection.Parent.FileName: C:\Users\JoeAdmin\Documents\RestWinHttpReference.xlsm


----------



## joethall (Jul 16, 2008)

Just an additional note to indicate that the error message cited above mentions DllUnregisterServer and at least *http://msdn.microsoft.com/en-us/library/ms691457(VS.85).aspx* suggests that the base information is somewhere in the registry.


----------



## Glaswegian (Sep 16, 2005)

Hi Joe

The only thing I could find on this subject (at least that provided any help) was this

http://groups.google.com/group/wind...&q=Error+loading+winhttp.dll#e06e2ad8b20c1899

Try following the guidance in the last post, especially the bit about disabling UAC.


----------



## joethall (Jul 16, 2008)

ray:Hallelujahray:

Re-installing the WinHttp library, but with UAC turned off, solved the problem!

I couldn't be happier!!

Thanks to EVERYONE who chipped in with advice and ideas.

But special thanks to Glaswegian who hit upon the UAC magic.

Thanks

joethall


----------



## Glaswegian (Sep 16, 2005)

Glad it worked for you.


----------

