Frage

Ich habe Code in Excel VBA erstellt, um eine PowerPoint-Präsentation 1 Folie für jede Excel-Zeile zu erstellen und in ein bestimmtes Textfeld in PowerPoint einzufügen.
Ich möchte jetzt alle Bilder hinzufügen, die der Beschreibung entsprechen.Dies sind alles Jpegs und keine Diagramme usw.
Wie kann ich das machen, und ist es besser, dies in Excel zu tun, oder ist es besser, dieses Powerpoint VBA selbst zu machen?
Auf jeden Fall, könnte mir bitte jemand mit einem Code helfen, wie das geht?
Die Bilderrahmen sind bereits in PowerPoint vorhanden.Es gibt 2 Bilder pro Folie (keine Übergänge oder ähnliches).
Vielen Dank!

PS Ich verwende PowerPoint und Excel 2010 unter Windows 7.


Gibt es eine Möglichkeit, dies von Excel aus zu tun?Der Rest meines Codes ist in Excel und es wäre großartig, dies als Teil des Makros zu tun.
Grundsätzlich habe ich einen Dateispeicherort, den ich verwenden möchte, z.C:\insertfoldername\imagename .jpeg wird in Spalte H in der Tabelle angezeigt (ungefähr 400 Zeilen).
Die Powepoint-Vorlage, die ich verwende, hat den Bildrahmen (den in Powerpoint, über den Sie mit der Maus fahren, sagt.."Bild aus Datei einfügen".
Diese sind bereits dimensioniert und befinden sich an der richtigen Stelle.
Was ich tun möchte, ist, in Excel das Bild aus dem Dateipfad in Excel einzufügen und es in diesen bestimmten Bildrahmen einzufügen.
Wird das überhaupt möglich sein?

Grundsätzlich etwas, das das tun wird:
PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage(spath)

Unten ist der Code, den ich verwende.
**** Gibt den Dateipfad an.die JPG-Datei wird als 3. Spalte in der Excel-Tabelle festgelegt.

Sub CreateSlides()
'Dim the Excel objects
Dim objWorkbook As New Excel.Workbook
Dim objWorksheet As Excel.Worksheet

'Dim the File Path String
Dim strFilePath As String

'Dim the PowerPoint objects
Dim PPT As Object
Dim pptSlide As PowerPoint.Slide
Dim pptLayout As PowerPoint.CustomLayout
Dim pptNewSlide As PowerPoint.Slide
Dim str As String
Dim Title As String

Set PPT = GetObject(, "PowerPoint.Application")

PPT.Visible = True

'Get the layout of the first slide and set a CustomLayout object
Set pptLayout = PPT.ActivePresentation.Slides(1).CustomLayout

'Run the OpenFile function to get an Open File dialog box. It returns a String containing the file and path.
strFilePath = OpenFile()

'Open the Excel file
Set objWorkbook = Excel.Application.Workbooks.Open(strFilePath)

'Grab the first Worksheet in the Workbook
Set objWorksheet = objWorkbook.Worksheets(1)

'Loop through each used row in Column A
For i = 2 To objWorksheet.Range("A65536").End(xlUp).Row

Set PPT = GetObject(, "PowerPoint.Application")

Set pptNewSlide = PPT.ActivePresentation.Slides.AddSlide(PPT.ActivePresentation.Slides.Count + 1, pptLayout)

 'Get the number of columns in use on the current row
    Dim LastCol As Long
    Dim boldWords As String

    boldWords = "Line1: ,line2: ,Line3: ,Line4: "
    LastCol = objWorksheet.Rows(i).End(xlToRight).Column
    If LastCol = 16384 Then LastCol = 1 'For some reason if only column 1 has data it returns 16384, so correct it

    'Build a string of all the columns on the row
    str = ""
    str = "Line1: " & str & objWorksheet.Cells(i, 1).Value & Chr(13) & _
    "Line2: " & objWorksheet.Cells(i, 2).Value & Chr(13) & _
    "Line3: " & objWorksheet.Cells(i, 10).Value & Chr(13) & _
    "Line4: " & objWorksheet.Cells(i, 7).Value & Chr(13) & Chr(13) & _
    objWorksheet.Cells(i, 14).Value

 sfile = Cells(i, 3) & ".jpg" **** This is the jpg name

Set PPT = GetObject(, "PowerPoint.Application")

spath = "C:\test\"

'Write the string to the slide
pptNewSlide.Shapes(2).TextFrame.TextRange.Text = objWorksheet.Cells(i, 3).Value 'This enters the film Title
PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = str


BoldSomeWords PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(1), str, boldWords

'This is where I want to load in the Image.
'PPT.ActivePresentation.Slides(PPT.ActivePresentation.Slides.Count).Shapes(3).Picture = LoadPicture(spath) ' & sfile)
'PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage((spath))

Next
End Sub

Function OpenFile()
'Dim the File Dialog object and string
Dim objFileDialog As FileDialog
Dim strFile As String

'Set the objFileDialog to an instance of the FileDialog object
Set objFileDialog = Application.FileDialog(msoFileDialogFilePicker)

'Set the Properties of the objFileDialog object
objFileDialog.AllowMultiSelect = False
objFileDialog.ButtonName = "Select"
objFileDialog.InitialView = msoFileDialogViewDetails
objFileDialog.Title = "Select Excel File"
objFileDialog.InitialFileName = "C:\"
objFileDialog.Filters.Clear
objFileDialog.Filters.Add "Excel", "*.xls; *.xlsx", 1
objFileDialog.FilterIndex = 1

'Show the FileDialog box
objFileDialog.Show

'Set strFile to the first record of the SelectedItems property of our FileDialog
strFile = objFileDialog.SelectedItems(1)

'Return the File Path string
OpenFile = strFile
End Function
War es hilfreich?

Lösung

So fügen Sie Bilder in aktuell geöffneter PPT hinzu Picture PlaceHolders mit Excel.
Wir benutzten Early Binding hinzufügen der Microsoft PowerPoint 14.0 Object Library Referenz.

Bearbeitung1: Hinzufügen von DoEvents und einigen Erklärungen

Sub ImportPictureInPlaceHolderFromExcel()

    Dim oPPt As PowerPoint.Application
    Dim oPPtSlide As PowerPoint.Slide
    Dim oPPtShp As PowerPoint.Shape

    '~~> Get hold of PPt instance meaning your currently open PPT presentation
    Set oPPt = GetObject(, "Powerpoint.Application")
    '~~> Reference the first slide which should contain picture placeholders
    Set oPPtSlide = oPPt.ActivePresentation.Slides(1)

    '~~> Now check each shape in slide
    For Each oPPtShp In oPPtSlide.Shapes
        '~~> You only need to work on Picture place holders
        If oPPtShp.PlaceholderFormat.Type = ppPlaceholderPicture Then
            With oPPtShp
                '~~> Now add the Picture
                '~~> For this example, picture path is in Cell A1
                oPPtSlide.Shapes.AddPicture Range("A1").Value, msoFalse, msoTrue, _
                                .Left, .Top, .Width, .Height
                '~~> Insert DoEvents here specially for big files, or network files
                '~~> DoEvents halts macro momentarily until the 
                '~~> system finishes what it's doing which is loading the picture file
                DoEvents
            End With
        End If
    Next

    Set oPPtSlide = Nothing
    Set oPPt = Nothing

End Sub

Summieren:
1.Wir besorgen uns eine PPT-Bewerbung
2.Wir erfassen die Folie und die Formen innerhalb der Folie
3.Jetzt wählen wir Formen, die sind ppPlaceholderPicture nur Typ
4.Wir verwenden die Shape Object's(Pppplatzhalterbildtyp) .Top, .Left, .Width and .Height eigentum als Argument für Shapes Kollektion .AddPicture Methode.

Und los geht's, Sie haben Ihrem PPT-Bildplatzhalter ein Bild hinzugefügt.
Hoffe, das ist was du brauchst.

Andere Tipps

Während das sieht aus wie es funktioniert, wenn Sie einer Folie ein Bild mit einem leeren Bild- oder Inhaltsplatzhalter hinzufügen, das immer in diesen Platzhalter eingefügt und in der Größe angepasst wird.

Sie müssen es nur so hinzufügen:

osld.Shapes.AddPicture "Path", msoFalse, msoTrue, -1, -1
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top