【问题标题】:Copy PowerPoint user input data to open Excel spreadsheet复制 PowerPoint 用户输入数据以打开 Excel 电子表格
【发布时间】:2021-06-03 13:10:52
【问题描述】:

我在 Powerpoint 中有一个宏,用户可以在其中输入数据。我希望将此数据保存在已打开的电子表格中。

如何使 PowerPoint 与电子表格进行通信?

我明白了

错误 9:下标超出范围。

Sub SaveBatchNo()

Dim strResult As String
strResult = InputBox("Please enter batch number.")

Workbooks("PP test.xlsx").Worksheets(1).Range("A1").Value = strResult

SlideShowWindows(1).View.GotoSlide 2

End Sub

【问题讨论】:

    标签: excel vba powerpoint


    【解决方案1】:

    一种方法如下:

    Sub SaveBatchNo()
        Dim strResult As String
        Dim ExcelApp As Object, WB As Object
        
        strResult = InputBox("Please enter batch number.")
        
        On Error GoTo errHandler    'https://docs.microsoft.com/ru-ru/office/vba/language/reference/user-interface-help/on-error-statement
        
        Set ExcelApp = GetObject(, "Excel.Application") ' get Excel application if it's running
        Set WB = ExcelApp.Workbooks("PP test.xlsx") ' get Workbook "PP test.xlsx" if it's opened
        WB.Worksheets(1).Range("A1").Value = strResult
        
        On Error GoTo 0
        
        ActivePresentation.SlideShowSettings.Run    ' without this instruction the next instruction raises the error
      
        SlideShowWindows(1).View.GotoSlide 2
       
        Exit Sub
    errHandler:
       MsgBox "Running Excel app. with opened Workbook 'PP test.xlsx' not detected", vbCritical + vbOKOnly, "Sub SaveBatchNo()"
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      相关资源
      最近更新 更多