简体   繁体   English

Excel VBA到Powerpoint:将单元格复制到现有幻灯片中的文本框

[英]Excel VBA to Powerpoint: Copying a cell to textbox in an existing slide

I'm a beginning to excel vba exporting and control information to other programs. 我是开始擅长将vba导出并控制信息到其他程序的Excel。

The task: Nameplates need to be printed and distributed to personnel to label their equipment. 任务:需要印刷铭牌,并将其分发给人员以标记其设备。 We have a huge equipment masterlist, the necessary information (machine ID) is only in one column of the excel sheet. 我们有一个庞大的设备主列表,必要的信息(机器ID)仅在excel工作表的一栏中。 The template for the sticker is in powerpoint. 不干胶标签的模板在PowerPoint中。

The steps are: 这些步骤是:

  1. PowerPoint should open the template PowerPoint应该打开模板

  2. Excel should give one cell of information into one slide. Excel应将一张信息的单元格放到一张幻灯片中。

  3. A duplicate slide should be made of the template slide 模板幻灯片应制作一张重复的幻灯片
  4. Step number 2 should be repeated except now the program has moved onto a different slide and different cell to copy and paste. 重复步骤2,除非现在程序已移至另一张幻灯片和另一单元上进行复制和粘贴。

Here is my code so far: 到目前为止,这是我的代码:

    Sub Sammple()
   'Declaring Variables
    Dim TemplateName As String
    Dim pptpres As Object
    Dim mySlide As Object
    Dim myPresentation As Presentation
    Dim TextBox As Object
    Dim i As Integer
    Dim j As Integer

    Set pptpres = CreateObject("Powerpoint.Application")
       With pptpres
            .Visible = True
           .Presentations.Open ("FileNameHere")
            For i = 1 To 400
                .ActivePresentation.Slides(1).Duplicate.Item (1)
                Next
            For j = 3 To 514
                Cells(j, 4).Copy
                Next
        End With


End Sub

As you can tell, I've gotten the code down for excel to make 400 duplicate slides. 如您所知,我已经将Excel的代码下载下来,可以制作400张重复的幻灯片。 I can't quite understand how to make excel copy text from the cell to a textbox into powerpoint then do it over and over until it reaches the end of the column range. 我不太明白如何使excel将文本从单元格复制到文本框并转换为powerpoint,然后一遍又一遍地进行直到到达列范围的末尾。

Any help pointing in the right direction would be great. 指向正确方向的任何帮助都将非常有用。 You'd be saving me over 1000 copy and paste clicks. 您将为我节省超过1000次复制和粘贴点击。

Do you mean the following? 您是说以下意思吗?

When you have duplicated a PP slide with already a textbox defined in it, that you want to fill in the value of an excel cell into the textbox of your PP slide? 复制了已经定义了文本框的PP幻灯片后,是否要将excel单元格的值填写到PP幻灯片的文本框中?

That is if the textbox in every slide has the same name, you can check it by going to Powerpoint, select your object (textbox), go to Format, Selection Pane, and there you can see the name of your textbox. 也就是说,如果每个幻灯片中的文本框都具有相同的名称,则可以转到Powerpoint进行检查,选择对象(文本框),再转到“格式”,“选择窗格”,然后在其中可以看到文本框的名称。 In this case it is "Title 1" 在这种情况下,它是“标题1”

Dim pp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.slide
Set pp = CreateObject("PowerPoint.Application")

Set PPPres = pp.Presentations.Open ("Filenamehere")
Set PPSlide = PPPres.Slides.Add(Slidestart, ppLayoutTitleOnly)

Sheets("SHEET NAME OF EXCEL").Activate
PPSlide.Shapes("Title 1").TextFrame.TextRange.Text = cells(i,j).text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM