[英]Modify Excel VBA code to paste into specific ppt slides
我是該論壇的新手,而VBA又是幾個月。 我所有的編碼經驗都在Matlab上,到目前為止,我發現它比VBA容易得多。 我已經閱讀了論壇規則,並搜索了高低答案,但無濟於事。
我正在嘗試將不同的Excel范圍粘貼到PowerPoint的不同幻燈片中。 我想修改下面的代碼(摘自不同論壇答案的摘錄),以便將范圍粘貼到我表示的相應PowerPoint幻燈片中, 而不管活動幻燈片是什么。 我已經嘗試過“ gotoslide”,但沒有用,並使用了ppviewnormal,但這也沒有用。 然后,將在不同的幻燈片上針對不同范圍重復此代碼。 到目前為止,該代碼僅在我正在為其編寫幻燈片時才有效,並且我知道它與活動幻燈片有關,但似乎無法弄清楚如何修改代碼。 預先感謝您的幫助!
' Desired Range in Excel to be copied into ppt
Sheets("Summary").Activate
Range("A5:H40").Select
' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' Denote slide where range is to be copied
Set PPSlide = PPPres.Slides(5)
' Copy the range as a picture
Selection.CopyPicture Appearance:=xlScreen, _
Format:=xlPicture
' Paste the range
PPSlide.Shapes.Paste.Select
從最后一行刪除“ .Select”
這是您的代碼的較短版本:
' Initialize PowerPoint Object Library
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
' Copy the range as a picture
Sheets("Summary").Range("A5:H40").CopyPicture Appearance:=xlScreen, Format:=xlPicture
' Paste the range
PPPres.Slides(1).Shapes.Paste
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.