Skip to content

Excel.Run Macro is not woring in Electron #151

Description

@kyomic

i try three method to execute macro function, not working, it throw '无法运行“UpdateCellA1”宏。可能是因为该宏在此工作簿中不可用,或者所有的宏都被禁用。', The VBA code can be executed manually in Excel. Electron permission issues.?

UpdateCellA1 is my vbsName,

...
const excel = new winax.Object("Excel.Application");
const currentWorkbook = excel.ActiveWorkbook;
if (workbook) {
    const vbProject = workbook.VBProject;
    if( vbProject){
       const moduleName = vbComponent.Name;
       const vbComponent = vbProject.VBComponents.Add(1);
       vbComponent.CodeModule.AddFromString(vbaCode);
      try{
           // call with moduleName  not working
           excel.Run(`${moduleName}.${vbaCodeName}`, sheet);
      }catch(err){
          // call with not moduleName not working
           excel.Run(`${vbaCodeName}`, sheet);
      }
      const CodeName = workbook.CodeName;
      console.log("CodeName:", CodeName);
      const vbComponent2 = workbook.VBProject.VBComponents.Item(workbook.CodeName);
      vbComponent2.CodeModule.AddFromString(vbaCode);
      const funName = `ThisWorkbook.OrderMacro`;
      // call with SheetFunction not working!
      excel.Run(funName, "从Node.js调用");
   }
}
....

ENV:
Windows 10 Professional x64
node:v21.7.3
electron: "30.5.1",
winax:3.6.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions