Removeing an Object Library Reference with VBA runtime error 9

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi am working with Access 2010. I am want to remove a reference from the library with VBA
I am using the below function
Public Sub RemoveReference(strReferenceName As String)
Access.References.Remove Access.References(strReferenceName)
End Sub

Calling from an Event Procedure

Call RemoveReference("Microsoft Outlook 14.0 Object Library")

I have also tried RemoveReference("C:\Program Files (x86)\Microsoft Office\Office14\MSOUTL.OLB") but keep getting Runtime Error9 Subscripted out of Range

What I am missing

Thanks
L
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I am using the below function
Actually, it's a sub, which is a type of procedure, but it's not a function. Not sure why you'd want to removed a broken reference. If your application doesn't need it, don't include it in design. If it's needed but broken, better to fix it than remove it? Otherwise, something must be within that will eventually call it, thus causing an error if not an outright crash. Besides, will this be the only one that could be broken? Why not loop through the references and validate them, and if broken, get the GUID and path from a db table that lists where they would be stored - especially if you're working in a IT controlled environment where everything tends to be the same.

You call statement looks OK. I think the issue is your use of brackets and quotes around the remove statement. Suggest
Code:
Access.References.Remove strReferenceName
(assuming you have the rest of the syntax correct - I don't know about the Access preface since again, I have only written code to fix, not remove.
 
Upvote 0
Thanks I tried to remove the brackets but still cannot get it to work still getting Runtime Error9 Subscripted out of Range

The reference is not broken I just want to uncheck it with VBA instead of Tools > References and when unchecking it. I have been successful in checking it through VBA but cannot uncheck it

Thanks for your assistance
 
Upvote 0
Hi just an update
I found the below code and it does exactly what I wanted

Dim r As Reference

For Each r In References
If UCase(r.FullPath) = UCase("C:\Program Files (x86)\Microsoft Office\Office14\MSOUTL.OLB") Then
'MsgBox r.FullPath
References.Remove r
End If
Next r
Set r = Nothing

This is just a temporary fix. I have code to loop through a query and send emails. I want to change the procedure to a late binding.


L
 
Upvote 0
A minor point: if you post your code changes we might find that one error was replaced by another, otherwise, we're just guessing if it's that or should be focusing on what's left. Which, by the way, after researching, it seems you don't remove the reference by referring to its name. What you have now is a loop that removes the item from the references collection IF a property = something (FullPath=, or Name=, etc). As I mentioned, I've only dabbled in this to check if all the required references were set (according to a db table of references) and fix them if broken. In playing around with what you're doing, I found that it removes the reference from the list entirely, not just unselects it. If you want it back, you better know where to find the file.
I suspect you don't need to UCase anything - unless you have Option Compare set to binary.
 
Upvote 0
This is just a temporary fix. I have code to loop through a query and send emails. I want to change the procedure to a late binding.
Sounds like a good idea if you can do this - references are less of a problem when new office versions come out.
 
Upvote 0
Excel help please

EXCEL


I am seeking help with macros and a template that has a picture recurring on each page i need to switch the picture.

I also need help transferring data from a master to a workbook in excel


New to this! not sure if I'm in the right area not sure how to post
 
Upvote 0
Re: Excel help please

Suggest you read the Board Announcements near the top of your screen for help on how/what to post. Posting in the wrong forum thread on purpose is not cool. Hijacking a post for some unrelated issue you're having is even less so.

Look for the +Post New Thread button at the bottom of the list for the forum you should post in, and please do read the announcements.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,242
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top