How do I insert picture based on textbox value in PowerPoint

强颜欢笑 提交于 2020-01-25 08:14:31

问题


I have a code which extract data from Excel and insert it into multiple slides in the PowerPoint.

Dim I As Integer
Dim oXL As Object 'Excel.Aplication
Dim OWB As Object 'Excel.workbook
Dim oSId As Slide
Dim A As Integer
Dim B As Integer
Set oXL = CreateObject(“Excel.Application”)
Set OWB = oXL.Workbooks.Open(FileName:="FileName.xlsx")
A = InputBox(“Page From")
B = InputBox(“Page To")

For I = A To B

oSId.Shapes(“Title l").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“A" &
CStr(l)). Value
oSId.Shapes(“Subtitle 2").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“B" &
CStr(l)). Value
oSId.Shapes(“Text Placeholder 3").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“C" & CStr(l)).Value
oSId.Shapes(“Text Placeholder 4").TextFrame.TextRange.Text = OWB.Sheets(“Sheet1").Range(“D" & CStr(l)).Value

Next
OWB.CIose
oXL.Quit
Set OWB = Nothing
Set oXL = Nothing

End Sub

I want the code to insert picture automatically into PowerPoint based on the cell value of Excel.

For example:

In the PowerPoint Slide, Range A1 is "Apple", Range A2 is "Orange", Range A3 is "Pear"

I have a Folder D:\Users\User\Desktop\Picture\ containing picture of "Apple.jpg", "Orange.jpg", "Pear.jpg".

The code will insert the picture in folder to the slides.

Appreciate your help and guidance! Thank you.


回答1:


If I understand you correctly you have pictures name in excel Range("A1"). So you may need the code like e.g. below:

oSId.Shapes.AddPicture( _
   FileName:="D:\Users\User\Desktop\Picture\" & OWB.Sheets(“Sheet1").Range(“A" & CStr(l)).Value & " .jpg", _
   LinkToFile:=msoFalse, _
   SaveWithDocument:=msoTrue, Left:=50, Top:=30, Width:=100, Height:=50).Select


来源:https://stackoverflow.com/questions/58924799/how-do-i-insert-picture-based-on-textbox-value-in-powerpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!