返回列表 上一主題 發帖

[發問] excel 自動轉換 PPT

回復 1# xperia0603
請參考以下vba
  1. Sub CreatePowerPoint()

  2. 'Add a reference to the Microsoft PowerPoint Library by:
  3.     '1. Go to Tools in the VBA menu
  4.     '2. Click on Reference
  5.     '3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay

  6.     'First we declare the variables we will be using
  7.         Dim newPowerPoint As PowerPoint.Application
  8.         Dim activeSlide As PowerPoint.Slide
  9.         Dim cht As Excel.ChartObject
  10.      
  11.      'Look for existing instance
  12.         On Error Resume Next
  13.         Set newPowerPoint = GetObject(, "PowerPoint.Application")
  14.         On Error GoTo 0
  15.      
  16.     'Let's create a new PowerPoint
  17.         If newPowerPoint Is Nothing Then
  18.             Set newPowerPoint = New PowerPoint.Application
  19.         End If
  20.     'Make a presentation in PowerPoint
  21.         If newPowerPoint.Presentations.Count = 0 Then
  22.             newPowerPoint.Presentations.Add
  23.         End If
  24.      
  25.     'Show the PowerPoint
  26.         newPowerPoint.Visible = True
  27.    
  28.     'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
  29.         For Each cht In ActiveSheet.ChartObjects
  30.         
  31.         'Add a new slide where we will paste the chart
  32.             newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
  33.             newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
  34.             Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
  35.                
  36.         'Copy the chart and paste it into the PowerPoint as a Metafile Picture
  37.             cht.Select
  38.             ActiveChart.ChartArea.Copy
  39.             activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
  40.    
  41.         'Set the title of the slide the same as the title of the chart
  42.             activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text
  43.             
  44.         'Adjust the positioning of the Chart on Powerpoint Slide
  45.             newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15
  46.             newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125
  47.         
  48.             activeSlide.Shapes(2).Width = 200
  49.             activeSlide.Shapes(2).Left = 505
  50.             
  51.         Next
  52.      
  53.     AppActivate ("Microsoft PowerPoint")
  54.     Set activeSlide = Nothing
  55.     Set newPowerPoint = Nothing
  56.      
  57. End Sub
複製代碼

TOP

回復 4# xperia0603


    請附上檔案

TOP

        靜思自在 : 人要自愛,才能愛普天下的人。
返回列表 上一主題