在文件夹中有一些我要复制的文件并将其嵌入我的powerpoint幻灯片中。 我已经编写了一个代码,但它给出了错误“运行时错误。形状未知成员:此行无效请求:
Set obchart = pres.Shapes.AddOLEObject(100, 100, 200, 100, folderpath & fil.Name, True)
Sub copyfilestoppt()
Dim fso As Scripting.FileSystemObject
Dim fil As Scripting.file
Dim foldername As Scripting.Folder
Dim folderpath As String
Dim pres As PowerPoint.Slide
Dim obchart As Object
folderpath = "C:\Users\av\Desktop\Macro\Excel maacro"
Set fso = New Scripting.FileSystemObject
Set foldername = fso.GetFolder(folderpath)
Set pres = ActivePresentation.Slides(1)
'loop
For Each fil In foldername.Files
With ActivePresentation
Set pres = ActivePresentation.Slides(1)
Set obchart = pres.Shapes.AddOLEObject(100, 100, 200, 100, folderpath & fil.name, True)
End With
Next fil
Set obchart = Nothing
End Sub
答案 0 :(得分:0)
您忘记了路径和文件名之间的“\”,并且您错放了参数。试试这个:
Set obchart = pres.Shapes.AddOLEObject(100, 100, 200, 100, , folderpath & "\" & fil.Name, True)
' ^^^ ^^^^^^