Board logo

標題: [發問] excel 自動轉換 PPT [打印本頁]

作者: xperia0603    時間: 2013-10-11 11:34     標題: excel 自動轉換 PPT

小弟有點小麻煩
VBA 目前有借幾本書來看
可是最多都介紹提升效率的方法
-
想請問一下 如何 用 Excel 的 vba 自動轉換成 ppt
是否能轉 ? 還是不能轉 ?

請求大大們對我這位vba新手介紹一下
作者: genes    時間: 2013-10-17 02:15

回復 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
複製代碼

作者: c_c_lai    時間: 2013-10-17 06:47

回復 1# xperia0603
在應用 genes 樓主的 CreatePowerPoint() 函示時,記得要先開啟
Microsoft PowerPoint 14.0 Object Library  (2007 版本以上)
如果不知如何啟動,請看以下說明:

開發人員   --->   設定引用項目   --->   勾選
"Microsoft PowerPoint 14.0 Object Library"   --->  
確定。
作者: xperia0603    時間: 2013-10-24 15:32

謝謝喔  測試成功 可是 如果我今天EXCEL 有圖片 or 文字 想一併轉換 想請問 有什麼方法呢

還有 如何學習 vba 的 轉換呢
作者: genes    時間: 2013-10-24 16:19

回復 4# xperia0603


    請附上檔案
作者: xperia0603    時間: 2013-10-29 01:41

回復 5# genes


抱歉  最近忙於一些事情 耽擱了 vba的學習

目前卡在  


假設 我有這些數值

100        101        102        103        104
200        201        202        203        204
300        301        302        303        304
400        401        402        403        404
500        501        502        503        504


如何利用 vba 把這些數值 變成 長條圖 圓餅圖等 然後 轉換成 power point 上面的pag呢?
[attach]16504[/attach]
作者: Ling2050    時間: 2015-1-10 15:27

回復 2# genes


    您好,參考您所提供的 VBA,對我受益良多。

    想再詢問,對於由Excel VBA所拋轉出的ppt檔案,是否能如同EXCEL一般,再透過VBA可自動存檔或是指定到相關路徑等方法。




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)