【问题标题】:Unable to populate PowerPoint TextBox with value in Excel cell using VBA无法使用 VBA 在 Excel 单元格中填充 PowerPoint 文本框
【发布时间】:2013-05-12 23:22:29
【问题描述】:

现在一切都修复了..我忘记了我使用的是 activex 控件文本框,而不是“普通”的 PPT 文本框。这是填充单个文本框的正确基本代码。

感谢 David Zemens,我解决了我遇到的一些早期问题,但我仍然无法实现我的最终目标。他觉得最好开一个新帖子,所以就在这里。

我做的第一件事是打开 PPT 文件并复制第一张幻灯片。复制方法是复制幻灯片,但会导致其他问题,所以戴夫我一个解决方法改变他们复制主幻灯片的方式。下面是我写的代码,暂时不会编译。 (另外我已经修改为只写入一个文本框,而不是使用循环,一旦我开始工作,最终将完成)

任何建议都会有所帮助。如果您需要更多信息,请告诉我,谢谢!

valppt()

Dim PPT As PowerPoint.Application
Dim newslide As PowerPoint.SlideRange
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True

PPT.Presentations.Open ("C:\Documents\createqchart.pptx")

Range("F2").Activate
slideCtr = 1

Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
Set tb = newslide.Shapes("TextBox" & slideCtr)

slideCtr = slideCtr + 1

Do Until slideCtr > 2
    If slideCtr = 2 Then
       'tb.TextFrame.TextRange.Characters.Text = Format(ActiveCell.Value, "m/d/yyyy")
       tb.OLEFormat.Object.Value = Format(ActiveCell.Value, "m/d/yyyy")
    End If
    ActiveCell.Offset(0, 1).Activate
    slideCtr = slideCtr + 1

    If slideCtr = 38 Then
        Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
        ActiveCell.Offset(1, -25).Activate
    End If

Loop

结束子

【问题讨论】:

  • 正确的代码现在在原始问题中。我忘记了我使用的是 activex 文本框而不是普通文本框。
  • 您好!哪一行导致您出错?我注意到文本框的默认命名约定类似于TextBox 1,但您分配它们的方式是TextBox1。这肯定会导致错误。

标签: excel vba textbox powerpoint


【解决方案1】:

这是正确的代码。

Sub valppt()
Dim PPT As PowerPoint.Application
Dim newslide As PowerPoint.SlideRange
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True

PPT.Presentations.Open ("C:\Documents\createqchart.pptx")

Range("F2").Activate
slideCtr = 1

Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
Set tb = newslide.Shapes("TextBox" & slideCtr)

slideCtr = slideCtr + 1

Do Until slideCtr > 2
    If slideCtr = 2 Then
       'tb.TextFrame.TextRange.Characters.Text = Format(ActiveCell.Value, "m/d/yyyy")
       tb.OLEFormat.Object.Value = Format(ActiveCell.Value, "m/d/yyyy")
    End If
    ActiveCell.Offset(0, 1).Activate
    slideCtr = slideCtr + 1

    If slideCtr = 38 Then
        Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
        ActiveCell.Offset(1, -25).Activate
    End If

Loop
End Sub

【讨论】:

    猜你喜欢
    • 2013-05-11
    • 2020-06-08
    • 2017-11-19
    • 2014-06-13
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    相关资源
    最近更新 更多