我試圖記錄(1.什麼幻燈片和2.時間)到電子表格每次在演示模式下查看幻燈片。當我這樣做時,我不希望電子表格打開,我希望它自動保存。我一直在使用它幾個小時,而且我獲得了不同的成功。我似乎無法按預期工作。VBA PowerPoint寫入幻燈片的幻燈片更改
下面是到目前爲止我一起擠代碼:我沒有嘗試過的代碼進行
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim strSheet As String
Dim strPath As String
Dim curentSlide As Integer
Dim timez As Date
Dim z As Integer
strSheet = "test.xlsx"
strPath = "C:\PPToutput\"
strSheet = strPath & strSheet
Dim counter As Integer
counter = 0
counter = counter + 1
currentslide = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
timez = Now()
If Not IsNull(appExcel) And counter < 2 Then
Set appExcel = CreateObject("Excel.Application")
appExcel.Application.DisplayAlerts = False
appExcel.Workbooks.Open (strSheet)
Set wkb = appExcel.ActiveWorkbook
Set wks = wkb.Sheets(1)
wks.Activate
End If
appExcel.Application.Visible = True
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = "Slide " & currentslide
Range("B" & Rows.Count).End(xlUp).Offset(1).Value = timez
wks.Columns.AutoFit
wkb.SaveAs
Set appExcel = Nothing
appExcel.Workbooks.Close
appExcel.Quit
Set appExcel = Nothing
End Sub
具體說明哪一部分不按預期工作。通過「不想讓電子表格打開...」,你的意思是你不希望Excel可見或根本不打開?如果Excel未打開,那麼寫入範圍相當困難... –
讓我澄清一下:我希望Excel在寫入時隱藏在用戶的視圖中。這是爲了記錄從幻燈片到幻燈片以及從開始到結束的PowerPoint演示時間。 理想情況下,腳本將在後臺打開Excel,每次幻燈片更改時寫入一個新行,並在PowerPoint演示文稿結束時保存並關閉。希望上面編輯的代碼更易於閱讀。我知道代碼是有缺陷的。它會打開太多的Excel實例而無法正確寫入。 – mmcdon8
您使用的是什麼版本的PowerPoint?此代碼是否在加載項中運行? –