将 Excel 中的图表粘贴到特定布局中的特定占位符.电源点 2010 [英] Paste a chart from Excel to a specific placeholder in a specific layout. Powepoint 2010

查看:16
本文介绍了将 Excel 中的图表粘贴到特定布局中的特定占位符.电源点 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将多个图表从 excel 粘贴到 powerpoint.我发现了一些优秀的 VBA 代码(主要在 Jon Peltier 的网站上).现在我的 powerpoint 模板有多种布局(例如,一张图表占据了大部分幻灯片,或者一张图表和一个幻灯片中的一个文本框等).

I need to paste multiple charts from excel to powerpoint. I found some excellent VBA code (mainly on Jon Peltier's site). Now my powerpoint template has a number of layouts (e.g. with 1 chart occupying most of the slides or 1 chart and one text box in a slide, etc etc).

我想要的是图表成为幻灯片布局的一部分,这样如果我重新格式化幻灯片 - 例如我按照上面给出的示例更改布局 - 图表将相应移动.目前,我可以在占位符所在的位置粘贴合适的大小和所有内容,但它不在占位符中,而是在占位符上(因此,如果我更改布局,它会留在那里).

What I want is the chart to become part of the slide layout so that if I reformat the slide - e.g. I change the layout as in the example given above - the chart will move accordingly. Currently I am able to paste in the spot where the placeholder is, with right size and everything, but it is not IN the placeholder, it's ON the placeholder (and therefore it stays there if I change layout).

理想情况下,我希望能够选择布局(从 15 个)并在所选布局中选择占位符(通常我有一个标题、一个页脚,然后是 1 到 4 个用于图表、图像、文本或以上所有).

Ideally I would like to be able to choose the layout (from 15) and choose the placeholder in the selected layout (typically I have a title, a footer, and then from 1 to 4 placeholders for charts, images, text or all of the above).

我不是 VBA 程序员,我只是使用了一点逻辑和抓取代码,这些代码在网上很好地共享.我不知道如何识别正确的布局(它们有名字,但这是变量吗?)也不知道布局中的正确占位符(在这里我什至不知道如何识别它们).

I am not a VBA programmer, I just use a little bit of logic and grab codes which is kindly shared on the net. I have not clue how to identify the proper layout (they have names, but is that the variable?) nor the proper placeholder within the layout (here I do not even know how to identify them).

非常感谢任何帮助.东东

Any help much appreciated. DF

以下是我随处复制的代码(主要是 Jon Peltier 的网站).

In the following, the code I copied here and there (mainly Jon Peltier's site).

Sub ChartToPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim AddSlidesToEnd As Boolean

AddSlidesToEnd = True

' Make sure a chart is selected
If ActiveChart Is Nothing Then
  MsgBox "Please select a chart and try again.", vbExclamation, _
  "No Chart Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

' Copy chart
ActiveChart.ChartArea.Copy

' Paste chart
PPSlide.Shapes.Paste.Select

' Position pasted chart
' This is the keypoint
' I want to replace this with the selection of appropriate layout 
' and placeholder in that layout
PPApp.ActiveWindow.Selection.ShapeRange.Left = 19.56
PPApp.ActiveWindow.Selection.ShapeRange.Top = 66.33
PPApp.ActiveWindow.Selection.ShapeRange.Width = 366.8
PPApp.ActiveWindow.Selection.ShapeRange.Height = 424.62


If PPApp.ActivePresentation.Slides.Count = 0 Then

' Other key point
' can I add a specific layout, for example one named Two Content Layout + takeout
 Set PPSlide = PPApp.ActivePresentation.Slides.Add(1, ppLayoutBlank)
Else
    If AddSlidesToEnd Then
         'Appends slides to end of presentation and makes last slide active
        PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
        PPApp.ActiveWindow.View.GotoSlide PPApp.ActivePresentation.Slides.Count
        Set PPSlide = PPApp.ActivePresentation.Slides(PPApp.ActivePresentation.Slides.Count)
    Else
         'Sets current slide to active slide
        Set PPSlide = PPApp.ActiveWindow.View.Slide
    End If
End If


'Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing


End If

End Sub

推荐答案

如果我理解你的问题,那么我认为这就是你想要的.

If I understood your problem then I think this is what you want.

您当前正在粘贴图表开启"幻灯片 1.您必须将其粘贴到 Slide 1 中的In"相关Place Holder.

You are currently pasting the chart "On" Slide 1. You have to paste it "In" relevant Place Holder in Slide 1.

修改您的代码以包含此内容(尝试和测试)

Amend your code to incorporate this (TRIED AND TESTED)

Dim nPlcHolder As Long

With PPPres
    nPlcHolder = 2 '<~~ The place holder where you have to paste

    .Slides(1).Shapes.Placeholders(nPlcHolder).Select msoTrue
    .Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With

现在,即使您更改布局,图表也会相应移动.

Now even if you change your layout, the charts will move accordingly.

快照

HTH

这篇关于将 Excel 中的图表粘贴到特定布局中的特定占位符.电源点 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆