Are the macros allowed?

M

Milan

Hello,

I would like to ask you which VBA property or command should I use if
I want to know if the user allowed usage of macros when he was opening
some Excel file.

Thanks in advance,
Milan.
 
D

Dave Peterson

If the user allowed macros to run, then you can use anything you want.

But if the user didn't allow macros to run, then any code you try to use won't
be running--so it wouldn't matter.
 
M

Milan

Thank you. Maybe my question was not written exactly. I have developed
an application in Access which cooperates with some Excel file which
has been opened by user before. I would like to know how can I find
out in Access (i use the command GetObject) if the macros are enabled
or disabled in the opened Excel file. Of course I know how to find it
out but I wonder if there is some simple elegant way.

Thanks, Milan.
 
D

Dave Peterson

If you have control over that excel file, can you add a test function?

Option Explicit
Function testme01() As Boolean
testme01 = True
End Function

I don't use Access, but this seemed to return good stuff when called from
MSWord:

Option Explicit
Sub testme()

Dim xlApp As Object
Dim wkbk As Object
Dim macsAvailable As Boolean

Set xlApp = Nothing
On Error Resume Next
Set xlApp = GetObject(, "excel.application")
On Error GoTo 0

If xlApp Is Nothing Then
MsgBox "excel isn't running!"
Exit Sub
End If

Set wkbk = xlApp.activeworkbook

On Error Resume Next
macsAvailable = xlApp.Run(wkbk.Name & "!testme01")
On Error GoTo 0

If macsAvailable Then
MsgBox "macs are available"
Else
MsgBox "macs not available"
End If

End Sub
 
Top