Cannot run the macro… the macro may not be available in this workbook

I am trying to call a sub on a different worksheet but I got a run time error message.

Specifically, I have two worksheets and multiple VBA sub s in those worksheets. In one of the VBA Project (say workbook1.xlsm), I have the following code:

Sub AnalysisTableMacro()
Workbooks("Python solution macro.xlsm").Activate
Application.Run "Python solution macro.xlsm!.PreparetheTables"
End Sub

But I got the following error. The macros on both worksheets are enabled. In both worksheets, the subs are in Module1.

Cannot run the macro 'Workbook.xlsm!PrepareTheTables'. The macro may not be available in >this workbook or all macros may be disabled.

I also tried Application.Run "Python solution macro.xlsm!Module1.PreparetheTables" but did not work.

Any help would be appreciated.


Per Microsoft's KB, try allowing programmatic access to the Visual Basic project:

  1. Click the Microsoft Office Button, and then click Excel Options.
  2. Click Trust Center.
  3. Click Trust Center Settings.
  4. Click Macro Settings.
  5. Click to select the Trust access to the VBA project object model check box.
  6. Click OK to close the Excel Options dialog box.
  7. You may need to close and re-open excel.

Delete your name macro and build again. I did this, and the macro worked.

The most probable reason for this error is that the security feature in Excel VBA that would not allow the VBA code to be run. The user should explicitly give permission to running the excel macros alongside the workbook. This may or may not require programmatic access to the Visual Basic project.

What solved this error for me was :-

  1. Enable Editing and Enable Content

  2. Changing macro settings without programmatic access Steps and details
  3. Changing macro settings along with programmatic access(not recommended if the any of the above process works out. This would give code control to change the elements in the VBA Project itself including References and Code itself - Reference)

    Steps Here

I had the same problem as OP and found was due to the options declaration being misspelled:

' Comment comment  

Options Explicit  

Sub someMacroMakechart()

in a sub module, instead of correct;

' Comment comment  

Option Explicit  

Sub someMacroMakechart()

If you have a space in the name of the workbook you must use single quotes (') around the file name. I have also removed the full stop.

Application.Run "'Python solution macro.xlsm'!PreparetheTables"

Need Your Help

Debugging sub-queries in TSQL Stored Procedure

sql-server-2005 tsql debugging visual-studio-2005

How do I debug a complex query with multiple nested sub-queries in SQL Server 2005?

Strategy for desugaring Haskell

compiler-construction haskell lambda-calculus

I'm developing a virtual machine for purely functional programs, and I would like to be able to test and use the the wide variety of Haskell modules already available. The VM takes as input essent...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.