将文本从Excel单元格复制到PPT文本框 [英] copy text from Excel cell to PPT textbox

查看:257
本文介绍了将文本从Excel单元格复制到PPT文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用excel-vba将文本从Excel中的单元格复制到PPT中的文本框。
我有以下代码:

I have to copy text from a cell in Excel to a textbox in PPT using excel-vba. I have the following code:

 ActivePresentation.Shapes(tb).TextFrame.Characters.Text = ActiveSheet.Range("C41").Value

但是这个代码是给出错误方法或数据成员bot发现为形状。有什么正确的方法?

But this code is giving the error "method or data member bot found" for Shapes. What is the correct way to do it?

提前感谢

推荐答案

p>您收到错误,因为您没有指定形状在哪里。我的意思是哪个幻灯片???

You are getting an error becuase you have not specified where the shape is. I mean which slide???

看这个例子。 (从Excel中测试过)

See this example. (tried and tested from Excel)

根据需要修改

代码

Option Explicit

Sub Sammple()
    Dim oPPApp As Object, oPPPrsn As Object, oPPSlide As Object
    Dim oPPShape As Object
    Dim FlName As String

    '~~> Change this to the relevant file
    FlName = "C:\MyFile.PPTX"

    '~~> Establish an PowerPoint application object
    On Error Resume Next
    Set oPPApp = GetObject(, "PowerPoint.Application")

    If Err.Number <> 0 Then
        Set oPPApp = CreateObject("PowerPoint.Application")
    End If
    Err.Clear
    On Error GoTo 0

    oPPApp.Visible = True

    '~~> Open the relevant powerpoint file
    Set oPPPrsn = oPPApp.Presentations.Open(FlName)
    '~~> Change this to the relevant slide which has the shape
    Set oPPSlide = oPPPrsn.Slides(1)
    '~~> Change this to the relevant shape
    Set oPPShape = oPPSlide.Shapes(1)

    '~~> Write to the shape
    oPPShape.TextFrame.TextRange.Text = _
    ThisWorkbook.Sheets("Sheet1").Range("C41").Value

    '
    '~~> Rest of the code
    '
End Sub

这篇关于将文本从Excel单元格复制到PPT文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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