Azzera filtri
Azzera filtri

Issues in Running VBA macros programmatically from Matlab

5 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

dpb
dpb il 31 Lug 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 Commento
Vish
Vish il 1 Ago 2024
Indeed it was the MS security settings as some of them were controlled by my organization. Thanks!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Export to MATLAB in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by