我的代碼應該將圖片,範圍和文本框從Excel導出到PowerPoint。我得到一個錯誤,雖然它應該將範圍粘貼爲位圖。該錯誤指出未找到變量。我是VBA新手,如果可能的話需要一些幫助。粘貼時未找到變量
這裏是代碼我使用:
Option Explicit
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Sub copy_to_ppt()
Dim wsname As String
Dim Shapes As Shape
Dim Range As Range
Dim a, b As Integer
Set PPApp = New PowerPoint.Application
PPApp.Visible = True
Set PPPres = PPApp.Presentations.Open("C:\Users\gdjwherr\Desktop\Brazil Reports\TRP File\TRP Test Template.pptx")
Sheets("Sheet1").Select
'-----------------------------
ActiveSheet.Shapes("Picture 1").Select
Selection.Copy
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
PPApp.ActiveWindow.ViewType = ppViewSlide
PPSlide.Shapes.PasteSpecial(ppPasteJPG).Select
PPApp.ActiveWindow.Selection.ShapeRange(1).Top = PPApp.ActiveWindow.Selection.ShapeRange(1).Top + 60
PPApp.ActiveWindow.Selection.ShapeRange(1).Left = PPApp.ActiveWindow.Selection.ShapeRange(1).Left + 20
ActiveSheet.Range("D3:E8").Select
Selection.Copy
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
PPApp.ActiveWindow.ViewType = ppViewSlide
Selection.PasteSpecial DataType:=wdPasteBitmap ```This is where the error occurs stating variable not defined and highlights wdPasteBitmap
PPApp.ActiveWindow.Selection.ShapeRange(1).Top = PPApp.ActiveWindow.Selection.ShapeRange(1).Top + 60
PPApp.ActiveWindow.Selection.ShapeRange(1).Left = PPApp.ActiveWindow.Selection.ShapeRange(1).Left + 0
ActiveSheet.Range("G3:H8").Select
Selection.Copy
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
PPApp.ActiveWindow.ViewType = ppViewSlide
Selection.PasteSpecial DataType:=wdPasteBitmap
PPApp.ActiveWindow.Selection.ShapeRange(1).Top = PPApp.ActiveWindow.Selection.ShapeRange(1).Top + 60
PPApp.ActiveWindow.Selection.ShapeRange(1).Left = PPApp.ActiveWindow.Selection.ShapeRange(1).Left - 20
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
你能與任何堆棧跟蹤沿後確切的錯誤信息? –
'wdPasteBitmap'看起來像一個Word VBA常量 - 這不會在Excel VBA中可用。您可能需要'ppPasteBitmap' –
@Tim Williams確定已更改爲'ppPasteBitmap',現在出現運行時錯誤1004應用程序定義或對象定義的錯誤? – William