通过VBA编辑PowerPoint图表-Office365

时间:2019-02-26 12:34:59

标签: vb.net office365 powerpoint-vba

我需要一些脚本。首先,直到我们更改为Office365,我的脚本才能正常工作。但是现在有一些我不理解的奇怪的随机错误。 我的主题是什么:我有一个用户表单,可以在其中填写一些值。此值对于更新PowerPoint文档中的多个图表是必要的。第一次导入工作正常,但第二次导入失败。 chartdata表丢失。有人有解释吗?

在下面,您会找到我的代码。

    Option Strict On
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    Imports System.IO

    Public Class Eingabemaske
    Private Sub ButtonGutachtenErstellen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGutachtenErstellen.Click

    Dim AppPfad As String = Application.StartupPath

    Dim PPT As PowerPoint.Application
    Dim PPTDoc As PowerPoint.Presentation
    Dim Chart As PowerPoint.Chart

    Dim WorkBook As Excel.Workbook
    Dim WorkSheet As Excel.Worksheet

    Dim PPTPfad As String = "Vorlagen\Gutachtenvorlage.potx"


    PPT = CType(CreateObject("PowerPoint.Application"), PowerPoint.Application)
    If File.Exists(Path.Combine(AppPfad, PPTPfad)) Then
        PPTDoc = PPT.Presentations.Open(Path.Combine(AppPfad, PPTPfad), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoCTrue)
        LabelStatus.Text = "Die Dokumentenvorlage wurde geladen."
    Else
        MsgBox("Die Dokumentenvorlage konnte nicht geöffnet werden. Bitte überprüfen Sie, ob die Datei vorhanden ist. Es wurde kein Gutachten erstellt.")
        PPT.Quit()
        PPTDoc = Nothing
        LabelStatus.Text = "Gutachtenerstellung fehlgeschlagen!"
        Exit Sub
    End If

        With PPTDoc.Slides(1).Shapes
            If CBool(.Item("Contentshape").HasChart) Then
                Chart = CType(.Item("Contentshape").Chart, PowerPoint.Chart)
                Chart.ChartData.Activate()
                WorkBook = CType(Chart.ChartData.Workbook, Excel.Workbook)
                WorkSheet = CType(WorkBook.Sheets(1), Excel.Worksheet)

                With WorkSheet
                    .Range("C7").Value = #wert
                End With

                WorkBook.Close()
            End If

结尾

0 个答案:

没有答案