Borrar filtros
Borrar filtros

Issues in Running VBA macros programmatically from Matlab

5 visualizaciones (últimos 30 días)
Vish
Vish el 31 de Jul. de 2024
Comentada: Vish el 1 de Ag. de 2024
Hello,
When I try to open my VBA macro enabled excel directly and run the macro within excel, it works fine. However, when I try to do the same operation using Matlab script, it shoots these error messages. Does anyone has any idea?
% Test Script VBA Code access and run
ExcelApp = actxserver('Excel.Application'); % Create object
ExcelApp.Visible = 1; % Show window (optional).
macrobook = ExcelApp.Workbooks.Open(fullfile('C:\Pro','\Test.xlsm')); % Open file
retVal = ExcelApp.Run('Macro1'); % Run Macro1
I have checked my macro settings in excel and they are all enabled:
I have also attached a simple macro enabled file example.

Respuesta aceptada

dpb
dpb el 31 de Jul. de 2024
Just ran a simple test here and no problems...
I have had issues in the past with the new MS security settings are much more aggressive than used to be; particularly had trouble if the workbook came from the network drive and tried to work on a local copy; it would disable macros regardless.(*)
Had to go into Trust Center and add trusted locations to include the network for trusted documents as well as just checking the macro settings.
(*) Just discovered that the test ran while the workbook was still open after writing the little macro; when I closed it and reopened it, the "Enable VBA macros..." checkbox was unchecked again so had to physically check it yet again. Be sure it really is allowed and not just letting you get by because you're in the developer mode and writing the macro.
  1 comentario
Vish
Vish el 1 de Ag. de 2024
Indeed it was the MS security settings as some of them were controlled by my organization. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Export to MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by