Avatar of shieldsco
shieldscoFlag for United States of America

asked on 

Access Compile Error Type Mismatch

I'm using the code below and get a type mismatch compile error on :
"(C:\Program Files (x86)\Microsoft Office\Office16\Excel.exe)"





Sub RemoveReferences()

'try to Remove a reference to Excel
On Error GoTo CanNotRemoveExcel
Application.VBE.ActiveVBProject.References.Remove "(C:\Program Files (x86)\Microsoft Office\Office16\Excel.exe)"



Exit Sub
CanNotRemoveExcel:
MsgBox "Can not reference Excel"
End Sub

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
shieldsco
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Try removing the parentheses ...

That said - removing a reference via code can cause all sorts of issues. What exactly are you trying to do?
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

same issue
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

compile error can't find project or library

Dim ref As Access.Reference
 For Each ref In Application.References
     If UCase(ref.FullPath) = UCase("C:\Program Files (x86)\Microsoft Office\Office14\excel.exe") Then
         Application.References.Remove ref
         Exit For
     End If
 Next ref
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

runtime error 48 loading dll

Application.References.Remove Application.References("Excel")
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Then your code and/or file is corrupted.
If Excel is not referenced, the error will be 9: Subscript out of range
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

Neither the file or the code is corrupt
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Then it is the Office install. That loading error is not related to this piece code.
compile error can't find project or library
What version of Access? I'm using 2016, and the code runs as expected. I added an Excel reference, modified the path so it pointed to the correct location on my machine, and ran my code. I worked as expected, with no errors, and removed the reference.

I also tested Gustav's code, and it worked as expected - it removed the reference, and did not produce an error.

As Gustav has indicated, something else is going on with your application.
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

Some users are running 2010 and others 2016
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

I went with late binding which solved my different version issues.
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

Thanks to all
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo