【问题标题】:VB.NET Closing Workbook of ChartdataVB.NET 关闭图表数据工作簿
【发布时间】:2020-08-02 18:32:09
【问题描述】:

希望你们都平安健康!

我想要做什么: 使用 VB.NET 我打开一个 Powerpoint 模板并更新位于所述模板中的图表。 奇怪的是,直到最近,这还不错,但让我们暂时忘记这一点。

问题出在哪里?: 问题开始了,任务在哪里结束 -> 在我完成更新后,我似乎无法关闭 chartData 的工作簿。 我收到以下错误消息:

System.Runtime.InteropServices.COMException:HRESULT 的 Exceltion:0x800A03EC

我的代码(简化)如下所示:(错误出现在代码底部)

'Preparing the Variables
Dim j As Integer
Dim slide = pp.Slides(1)
Dim shape = slide.Shapes
slide = pp.Slides(5)
shape = slide.Shapes
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim chart As PowerPoint.Chart

'Prepare the Chart
chart = shape.Item("Diagramm 13").Chart
'Access the ChartData
chart.ChartData.Activate()
wb = CType(chart.ChartData.Workbook, Excel.Workbook)
ws = CType(wb.Sheets(1), Excel.Worksheet)
ws.UsedRange.ClearContents()

wb.Close()     '<--This is where it stops and throws a 
               '"System.Runtime.InteropServices.COMException: HRESULT: 0x800A03EC" Exception
wb = Nothing

我已经尝试过的:

  • 我尝试在 ChartData.Activate() 行之后立即关闭它
  • 我尝试在 ChartData.Activate() 行之后立即用“chart.ChartData.Workbook.Close”关闭它
  • 在关闭 wb 之前再次激活它
  • 通过将 wb.name 写入变量来检查 wb 的名称是否以某种方式更改 -> 看起来它的名称正确。

你知道这里有什么问题吗? 这里是 如果需要,我可以提供更多信息!

感谢您的帮助和时间,

最好, 亚历克斯

更新:

我今天早些时候创建了一个版本,因为我没想到会出现这些问题。当我当时正在修复它们时,我的一位同事实际上能够在没有错误的情况下运行该版本......我现在完全糊涂了。这么简单的代码真的会因为我电脑上的一些随机更新而停止工作吗?

【问题讨论】:

    标签: .net excel vb.net powerpoint excel-interop


    【解决方案1】:

    遗憾的是,我无法尝试 Marco Hönsch 提供的建议。

    我重新安装了我的 Office,并从 Office 16 升级到了 Office 19。 该代码立即再次起作用。 遗憾的是,我无法提供准确的答案,因为它可能是一个损坏的办公室,导致了这个错误。或者问题与office版本本身有关。

    不管怎样,它现在可以工作了。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题(在 C# 中)。

      更换...

      wb.Close()
      

      ...与...

      wb.Application.Quit() 
      

      ...在我的情况下解决了它!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-24
        • 1970-01-01
        • 2019-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多