【问题标题】:Sorry, we couldn't find Test.xlsm. Is it possible it was moved, renamed or deleted?抱歉,我们找不到 Test.xlsm。它有可能被移动、重命名或删除吗?
【发布时间】:2015-05-26 01:02:21
【问题描述】:

我正在从我的 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();

【问题讨论】:

  • Test.xlsm 是否在项目子文件夹中?

标签: c# macros clickonce xlsm


【解决方案1】:

我找到了解决方案。我在文件名前添加了Application.StartupPath:

string workbookPath = Application.StartupPath + @"\Test.xlsm";
//~~> Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open(workbookPath);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 1970-01-01
    • 2016-02-07
    • 2019-02-10
    相关资源
    最近更新 更多