复制PowerPoint用户输入数据以打开Excel电子表格
我在Powerpoint中有一个宏,用户在其中输入数据。我希望此数据保存在已打开的电子表格中 如何使PowerPoint与电子表格进行通信 我明白了 错误9:下标超出范围复制PowerPoint用户输入数据以打开Excel电子表格,excel,vba,powerpoint,Excel,Vba,Powerpoint,我在Powerpoint中有一个宏,用户在其中输入数据。我希望此数据保存在已打开的电子表格中 如何使PowerPoint与电子表格进行通信 我明白了 错误9:下标超出范围 Sub SaveBatchNo() 作为字符串的Dim strResult strResult=InputBox(“请输入批号”) 工作手册(“PP test.xlsx”)。工作表(1)。范围(“A1”)。值=stresult 幻灯片窗口(1).View.GotoSlide 2 端接头 一种方法如下: Sub SaveBatc
Sub SaveBatchNo()
作为字符串的Dim strResult
strResult=InputBox(“请输入批号”)
工作手册(“PP test.xlsx”)。工作表(1)。范围(“A1”)。值=stresult
幻灯片窗口(1).View.GotoSlide 2
端接头
一种方法如下:
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