简体   繁体   中英

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.

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. The template for the sticker is in powerpoint.

The steps are:

  1. PowerPoint should open the template

  2. Excel should give one cell of information into one slide.

  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.

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. 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.

Any help pointing in the right direction would be great. You'd be saving me over 1000 copy and paste clicks.

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?

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. In this case it is "Title 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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