[算表] 透由VBA複製Excel儲存格到PPT的指令(內詳)
軟體:MS Office
版本:2010
一般在Excel直接選擇一特定範圍(例如A1:C12)複製並於PPT貼上時,會產生一個類似表格的物件,
可快速進行簡易編輯
但是透由巨集貼上時,卻會變成一個內嵌的Excel檔案,如果要編輯的時候就會切換成一個類似Excel的編輯器
有辦法透由巨集貼上一個簡易的表格物件嗎?
目前的測試巨集內容如下:
Option Explicit
Sub ExcelRangeToPowerPoint()
'PURPOSE: Copy/Paste An Excel Range Into a New PowerPoint Presentation
'SOURCE: www.TheSpreadsheetGuru.com
Dim rng As Range
Dim PowerPointApp As Object, myPresentation As Object, mySlide As Object, myShape As Object
'Copy Range from Excel
Set rng = ThisWorkbook.ActiveSheet.Range("A1:C12")
'Create an Instance of PowerPoint
On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
Err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If
On Error GoTo 0
'Optimize Code
Application.ScreenUpdating = False
'Create a New Presentation
Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
'Copy Excel Range
rng.Copy
'Paste to PowerPoint and position
mySlide.Shapes.PasteSpecial DataType:=10 ' 2 = ppPasteEnhancedMetafile
'10 = ppPasteOLEObject
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
'Set position:
myShape.Left = 66
myShape.Top = 152
'Make PowerPoint Visible and Active
PowerPointApp.Visible = True
PowerPointApp.Activate
'Clear The Clipboard
Application.CutCopyMode = False
End Sub
--
┌─────────────────────────────┐
│就這樣,終於到了啟程的日子。 │
│和來機場送行的朋友們說著玩笑話,其實內心恍恍惚惚像在作夢。│
│也似乎是因為,為了走到「出發」這一步,耗盡了全部心力。 │
└─────────────────石田裕輔《不去會死!》─┘
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.137.40.168
※ 文章網址: https://www.ptt.cc/bbs/Office/M.1499154145.A.5B2.html
→
07/04 15:59, , 1F
07/04 15:59, 1F
→
07/04 16:18, , 2F
07/04 16:18, 2F
→
07/04 16:43, , 3F
07/04 16:43, 3F
→
07/04 16:46, , 4F
07/04 16:46, 4F
→
07/04 16:46, , 5F
07/04 16:46, 5F
→
07/04 16:51, , 6F
07/04 16:51, 6F
→
07/04 16:51, , 7F
07/04 16:51, 7F
→
07/04 17:00, , 8F
07/04 17:00, 8F
→
07/04 17:38, , 9F
07/04 17:38, 9F
→
07/04 18:13, , 10F
07/04 18:13, 10F
→
07/04 18:19, , 11F
07/04 18:19, 11F
→
07/04 18:31, , 12F
07/04 18:31, 12F
→
07/04 18:31, , 13F
07/04 18:31, 13F
→
07/04 19:27, , 14F
07/04 19:27, 14F
→
07/04 21:10, , 15F
07/04 21:10, 15F
→
07/04 21:12, , 16F
07/04 21:12, 16F
→
07/05 07:10, , 17F
07/05 07:10, 17F
→
07/05 07:58, , 18F
07/05 07:58, 18F
→
07/05 08:33, , 19F
07/05 08:33, 19F
※ 編輯: foolkids (223.140.240.10), 07/05/2017 08:37:28
Office 近期熱門文章
PTT數位生活區 即時熱門文章