Are the macros allowed?

  • Thread starter Thread starter Milan
  • Start date Start date
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.
 
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.
 
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.
 
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
 

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