这个程序复制活跃的嵌入式图表作为一个图片从一个工作表,然后粘贴到积极的幻灯片演示文稿。这是相同的上述程序,但它使用(见早期与后期绑定)后期绑定;突出的变化,在绿色。在后期绑定变量的类型,具体参考的对象库必须取代通用对象变量和常量,必须更换的数字等值。我喜欢把简报等同于一个评论帮助文档的代码。
标签:
<无>
1. [代码]粘贴Excel Chart图表到当前PowerPoint幻灯片中(后期绑定)
跳至
[1]
[2]
[全屏预览]
01 | Sub ChartToPresentation() |
10 | If ActiveChart Is Nothing Then |
11 | MsgBox "Please select a chart and try again." , vbExclamation, _ |
15 | Set PPApp = GetObject(, "Powerpoint.Application" ) |
17 | Set PPPres = PPApp.ActivePresentation |
18 | PPApp.ActiveWindow.ViewType = 1 |
20 | Set PPSlide = PPPres.Slides _ |
21 | (PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) |
24 | ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _ |
28 | PPSlide.Shapes.Paste. Select |
31 | PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True |
32 | PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True |
002 | Private Sub RefreshRangeToSlide(PPApp As PowerPoint.Application, PPPres As PowerPoint.Presentation, ByRef RefShape As PowerPoint.Shape, order As Integer , iStart As Integer , iEnd As Integer , jStart As Integer , jEnd As Integer , leftPosition As Single , topPosition As Single , widthSize As Single , heightSize As Single , AlternativeText As String ) |
003 | Dim PPSlide As PowerPoint.Slide |
005 | Set PPSlide = PPPres.Slides(order) |
006 | RefShape.AlternativeText = "useless" |
007 | With Worksheets( "Sheet1" ) |
008 | .Range(.Cells(iStart, jStart), .Cells(iEnd, jEnd)).CopyPicture Appearance:=xlScreen, Format:=xlPicture |
010 | With PPApp.ActiveWindow |
012 | With .Selection.ShapeRange |
013 | .LockAspectRatio = msoFalse |
018 | .AlternativeText = AlternativeText |
023 | Private Sub RefreshShapeToSlide(PPApp As PowerPoint.Application, PPPres As PowerPoint.Presentation, ByRef RefShape As PowerPoint.Shape, order As Integer , ChartName As String , leftPosition As Single , topPosition As Single , weightSize As Single , heightSize As Single , AlternativeText As String ) |
024 | Dim PPSlide As PowerPoint.Slide |
025 | Dim Shape_Row As Integer |
026 | Dim Shape_Column As Integer |
027 | Dim myChar As ChartObject |
029 | Set PPSlide = PPPres.Slides(order) |
030 | RefShape.AlternativeText = "useless" |
031 | With Worksheets( "Sheet1" ) |
033 | .ChartObjects(ChartName).Chart.CopyPicture Appearance:=xlScreen, Format:=xlPicture |
035 | With PPApp.ActiveWindow |
037 | With .Selection.ShapeRange |
038 | .LockAspectRatio = msoFalse |
043 | .AlternativeText = AlternativeText |
047 | Private Sub RefreshChartLabelToSlide(PPApp As PowerPoint.Application, PPPres As PowerPoint.Presentation, ByRef RefShape As PowerPoint.Shape, order As Integer , leftPosition As Single , topPosition As Single , weightSize As Single , heightSize As Single , AlternativeText As String , ParamArray ShapeObjects() As Variant ) |
048 | Dim PPSlide As PowerPoint.Slide |
049 | Dim Shape_Row As Integer |
050 | Dim Shape_Column As Integer |
051 | Dim myChar As ChartObject |
053 | Set PPSlide = PPPres.Slides(order) |
054 | RefShape.AlternativeText = "useless" |
055 | With Worksheets( "Sheet1" ) |
057 | .Shapes.Range(Array(ShapeObjects(0), ShapeObjects(1))). Select |
060 | With PPApp.ActiveWindow |
061 | .View.PasteSpecial ppPastePNG |
062 | With .Selection.ShapeRange |
063 | .LockAspectRatio = msoFalse |
068 | .AlternativeText = AlternativeText |
073 | Sub ExcelToNewpowerPoint() |
075 | Application.ScreenUpdating = False |
078 | Dim FileName As String |
079 | Dim HasRefreshed As Boolean |
080 | Dim FilePath As String |
081 | Dim Templae As Boolean |
084 | Dim PPApp As PowerPoint.Application |
085 | Dim PPPres As PowerPoint.Presentation |
086 | Dim curSld As PowerPoint.Slide |
087 | Dim curShp As PowerPoint.Shape |
088 | Dim Sldorder As Integer |
089 | Dim leftPosition As Single , topPosition As Single , weightSize As Single , heightSize As Single |
090 | Dim ServiceData As Boolean , Template As Boolean |
092 | With Worksheets( "Sheet1" ) |
094 | FilePath = ThisWorkbook.Path |
095 | FilePath = FilePath & IIf(Right(FilePath, 1) <> "\", " \ ", " ") |
096 | fileSaveName = Application.GetSaveAsFilename(InitialFileName:= "http://MyTeamSpace/" & Country & "/" & City & "/" & Replace(FileName, "." , "" ) & ".pptx" , filefilter:= "powerPoint Sildes (*.pptx), *.pptx" ) |
097 | If fileSaveName <> False Then |
098 | Set objFSO = CreateObject( "Scripting.FileSystemObject" ) |
099 | Set PPApp = CreateObject( "PowerPoint.Application" ) |
102 | On Error GoTo Template |
103 | Set PPPres = .Presentations.Open(FileName:=fileSaveName) |
106 | Template: Set PPPres = .Presentations.Open2007(FileName:= "D:\Desktop\MondayWork.pptx" ) |
110 | .ActiveWindow.ViewType = ppViewNormal |
112 | For Each curSld In .Slides |
113 | If curSld.Shapes.Count > 0 Then |
114 | For Each curShp In curSld.Shapes |
115 | Select Case curShp.AlternativeText |
117 | If Not ServiceData Then |
118 | leftPosition = curShp.Left |
119 | topPosition = curShp.Top |
120 | weightSize = curShp.Width |
121 | heightSize = curShp.Height |
123 | RefreshChartLabelToSlide PPApp, PPPres, curShp, 3, leftPosition, topPosition, weightSize, heightSize, "ServiceData" , "Chart 1" , "TextBox1" |
128 | For Each curShp In curSld.Shapes |
129 | If curShp.AlternativeText = "useless" Then |
133 | For Each curShp In curSld.Shapes |
134 | If curShp.AlternativeText = "useless" Then |
138 | For Each curShp In curSld.Shapes |
139 | If curShp.AlternativeText = "useless" Then |
146 | On Error GoTo errorlog: |
147 | .SaveAs fileSaveName, ppSaveAsOpenXMLPresentation |
150 | Application.Visible = True |
162 | Application.ScreenUpdating = True |
164 | errorlog: MsgBox "请检查保存目录的访问权限!" |
|