我正在从我的 C# 应用程序运行宏代码。我已使用属性将 Test.xlsm 文件放置在项目本身中:
构建操作:将内容
复制到输出目录:始终复制。
但是,当我运行代码时,出现以下异常。
抱歉,我们找不到 Test.xlsm。它是否可能被移动、重命名或删除?
我无法提供硬编码路径,因为我必须创建此项目的 clickOnce 部署。
// Define your Excel Objects
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
//Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open("Test.xlsm");
// Run the macros by supplying the necessary arguments
xlApp.Run("Create", pFilePath1, pPath2);
// Clean-up: Close the workbook
xlWorkBook.Close(false);
// Quit the Excel Application
xlApp.Quit();