Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何在PowerPoint中基于文本框值插入图片_Excel_Vba_Powerpoint - Fatal编程技术网

Excel 如何在PowerPoint中基于文本框值插入图片

Excel 如何在PowerPoint中基于文本框值插入图片,excel,vba,powerpoint,Excel,Vba,Powerpoint,我有一个从Excel中提取数据并将其插入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.Ope

我有一个从Excel中提取数据并将其插入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
我希望代码根据Excel的单元格值自动将图片插入PowerPoint

例如:

在PowerPoint幻灯片中,范围A1为“苹果”,范围A2为“橙色”,范围A3为“梨”

我有一个文件夹
D:\Users\User\Desktop\Picture\
,里面有“Apple.jpg”、“Orange.jpg”、“Pear.jpg”的图片

代码将把文件夹中的图片插入幻灯片


感谢您的帮助和指导!谢谢。

如果我理解正确,您的图片名称在excel范围(“A1”)内。因此,您可能需要以下代码:

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

我已经试过密码了。它显示编译错误:语法错误,但我找不到错误。如果我删除了
.jpg
中的空格,它将返回编译错误:Expected=IMO存在错误的变量名,在整个循环代码中应该是“I”(大“I”-For循环的变量),而不是“l”(小l)。