首页 > 解决方案 > VBA 运行时错误 91,对象变量或未设置块变量

问题描述

我正在尝试将数据从excel复制到ppt。以下是我的代码的一部分...我在下面提到的行中遇到错误。问题是它大部分时间都在运行,但它突然开始抛出错误。请帮我找出相同的原因

 Dim pptChart As Chart
    Dim pptChartData As ChartData
    Dim sld As Slide
    Dim shp As Shape
    Dim wbk, wbk_copy As Workbook
    Dim wbk_paste As Worksheet
    Dim filepath As String
    Dim date_string As String
    
    filepath = ActivePresentation.Path
    
    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
    Set wbk_copy = xlApp.Workbooks.Open(filepath & "\development file.xlsm", True, False)
    'xlApp.Visible = True
    date_string = (wbk_copy.Worksheets("Data").Cells(10, 2))
    existing_date_string = (wbk_copy.Worksheets("Data").Cells(11, 2))
    wbk_copy.Close True
    Set xlApp = Nothing   
    For Each shp In sld.Shapes
      If shp.Name = "Title1" Then

        '##### Getting error on below line ####
          m = shp.TextFrame.TextRange.Find(existing_date_string).Characters.Start 
                    shp.TextFrame.TextRange.Characters(m).InsertBefore (date_string)
                    shp.TextFrame.TextRange.Find(existing_date_string).Delete
      End If

标签: excelvbaruntime-errorruntime

解决方案


推荐阅读