Removing references

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi I wonder if anyone can help with this. I am trying to use the
following code to remove a reference to a project in VBA so that I can
then close that workbook from with the active workbook.

The code seems to obey all the structures as set out in VBA help but
it, and as many variants as I can try, don't work.

Does anyone know how to do this

Many Thanks in anticipation

Steve

Code:-


Sub remref001()
Dim str001 As Reference
Set str001 = Application.VBE.ActiveVBProject.References(7)
str001.Remove
End Sub
 
UnTested...
try...
activeworkbook.VBProject.References.Remove(str001)
 
Sorry that was one of the variants I tried (tried it again though just
in case)

Basically the syntax seems OK but VBA comes back with "object doesn't
support this method"

Anyone any more ideas

Steve
 
using the () is a syntax violation - it evaluates the object and returns the
default value which isn't applicable as an argument. so removed the ()

activeworkbook.VBProject.References.Remove str001

so if you have a reference to the VBA extensibility Library

Sub AABB()
Dim str001 As Reference
Set str001 = ActiveWorkbook.VBProject.References(7)
ActiveWorkbook.VBProject.References.Remove str001
End Sub

if not

Sub AABB()
Dim str001 As Object
Set str001 = ActiveWorkbook.VBProject.References(7)
ActiveWorkbook.VBProject.References.Remove str001
End Sub
 
Tom

Brilliant as usual ! Many Thanks.

Steve

Tom Ogilvy said:
using the () is a syntax violation - it evaluates the object and returns the
default value which isn't applicable as an argument. so removed the ()

activeworkbook.VBProject.References.Remove str001

so if you have a reference to the VBA extensibility Library

Sub AABB()
Dim str001 As Reference
Set str001 = ActiveWorkbook.VBProject.References(7)
ActiveWorkbook.VBProject.References.Remove str001
End Sub

if not

Sub AABB()
Dim str001 As Object
Set str001 = ActiveWorkbook.VBProject.References(7)
ActiveWorkbook.VBProject.References.Remove str001
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top