كيفية إضافة الصور إلى عرض تقديمي ل Powerpoint الصورة نائبا?

StackOverflow https://stackoverflow.com//questions/23049917

سؤال

لدي بعض التعليمات البرمجية التي تم إنشاؤها في Excel VBA لإنشاء عرض تقديمي ل PowerPoint الشريحة 1 لكل صف من Excel ، و ملء محدد في مربع النص في PowerPoint.
أريد الآن أن أضيف في جميع الصور التي تتطابق مع الوصف.هذه كلها صور Jpeg وليس الرسوم البيانية وما إلى ذلك.
كيف يمكن أن أفعل هذا ، أنه من الأفضل أن تفعل هذا في excel ، أو أنه من الأفضل أن تفعل هذا Powerpoint VBA نفسها ؟
في كلتا الحالتين, أي شخص يكون قادرا على مساعدتي مع بعض التعليمات البرمجية على كيفية القيام بذلك من فضلك ؟
صورة إطارات موجودة بالفعل في PowerPoint.هناك 2 الصور في الشريحة (أي التحولات أو أي شيء).
شكرا لك!

P. S أنا باستخدام PowerPoint و Excel 2010 على ويندوز 7.


هل هناك طريقة للقيام بذلك من التفوق ؟ بقية الكود في Excel و سيكون من الرائع أن تفعل ذلك كجزء من الماكرو.
في الأساس لدي موقع الملف الذي أريد أن استخدام مثلC:\insertfoldername\imagename.jpeg يظهر في عمود ساعة في جدول البيانات (حوالي 400 الصفوف).
على Powepoint قالب أنا باستخدام لديه صورة إطار (واحد في Powerpoint ، wehn كنت تحوم فوق يقول.."إدراج صورة من ملف".
هذه هي بالفعل الحجم في الموقع الصحيح.
ما أريد القيام به هو ، في Excel ، لصق صورة من مسار الملف في excel السابقة إلى أن صورة معينة الإطار.
هل سيكون من الممكن على الإطلاق ؟

في الأساس شيء من شأنها أن تفعل هذا:
PPT.ActivePresentation.Slides(2).Shapes(3)LoadImage(spath)

أدناه هو رمز أنا باستخدام.
**** يشير إلى مسار الملف.jpg ملف يتم تعيين 3 عمود في جدول بيانات excel.

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
هل كانت مفيدة؟

المحلول

هذا كيف يمكنك إضافة الصور في الوقت الراهن فتح PPT Picture PlaceHolders باستخدام Excel.
كنا Early Binding إضافة Microsoft PowerPoint 14.0 Object Library المرجعية.

Edit1: مضيفا DoEvents و بعض التفسير

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

خلاصة القول المتابعة:
1.ونحن الحصول على عقد من تطبيق PPT
2.ونحن الحصول على عقد من الشريحة والأشكال داخل الشريحة
3.الآن نختار الأشكال التي ppPlaceholderPicture اكتب فقط
4.نستخدم Shape Object's(ppPlaceholderPicture نوع) .Top, .Left, .Width and .Height الملكية حجة الأشكال المجموعة .AddPicture الأسلوب.

و هناك تذهب ، إضافة صورة في PPT الخاص بك صورة العنصر النائب.
نأمل أن يكون هذا هو ما تحتاجه.

نصائح أخرى

في حين أن يبدو يعمل عند إضافة صورة إلى شريحة فارغ صورة أو محتوى نائبا وسوف تذهب دائما إلى أن نائب تغيير حجم لتناسب.

تحتاج فقط إلى إضافة مثل هذا:

osld.Shapes.AddPicture "Path", msoFalse, msoTrue, -1, -1
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top