View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
jh jh is offline
external usenet poster
 
Posts: 9
Default Trust access to the VBA project: Excel bug?, workaround required.

I'm fairly sure this is a VBA bug (comments welcome) and need a
workaround.

In Excel 2007 'm using the the function below in an add-in to return
the access oft the VBA project. It appears to work correctly.

Private Function IsVBProjectAvailable() As Boolean
Dim lngAccessTest As Long

On Error Resume Next
lngAccessTest = ThisWorkbook.VBProject.VBComponents.Count

If lngAccessTest 0 Then
IsVBProjectAvailable = True
Else
IsVBProjectAvailable = False
End If
End Function


....UNTIL you open a workbook containing macros. At that point unless
you ENABLE the macros the function then returns FALSE. The reason I'm
fairly sure its a bug is that a) it's the wrong answer and b) if you
then open the VBE (have it closed before you start, and don't do
anything except open it) the function then correctly returns TRUE

Any comments or suggestions for a workaround, or perhaps (hopefully)
I'm missing something obvious??!!

Thanks
John