|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 shenjianrong163 于 2021-10-28 23:25 编辑
试试这个。- Sub InsertMp3()
- '如果mp3有固定的顺序,事先在文件名前加“001、002、003……”
- Dim shp As Shape, L As Single, T As Single, W As Single, H As Single, Width As Single, Height As Single, i&, m&, arr
- On Error Resume Next
- Set myFolder = CreateObject("Shell.Application").BrowseForFolder(0, "GetFolder", 0)
- If Not myFolder Is Nothing Then myPath$ = myFolder.Items.Item.Path Else MsgBox "没有选择文件夹!": Exit Sub
- If Right(myPath, 1) <> "" Then myPath = myPath & ""
- arr = ListAllFsoDic(myPath)
- If UBound(arr) = -1 Then MsgBox "所选文件夹中没有mp3文件!请重新选择!": Exit Sub
- m = ActivePresentation.Slides.Count
- With ActivePresentation.PageSetup
- Width = .SlideWidth '页面宽度
- Height = .SlideHeight '页面高度
- End With
- L = Width - 60 '左边距
- T = Height - 50 '上边距
- W = 50 '宽度
- H = 50 '高度
- If m > UBound(arr) + 1 Then
- For i = 1 To UBound(arr) + 1
- With ActivePresentation.Slides(i)
- Set shp = .Shapes.AddMediaObject(arr(i - 1), L, T, W, H)
- End With
- Next
- Else
- For i = 1 To m
- With ActivePresentation.Slides(i)
- Set shp = .Shapes.AddMediaObject(arr(i - 1), L, T, W, H)
- End With
- Next
- End If
- End Sub
- Private Function ListAllFsoDic(myPath$, Optional k = 0)
- Dim i&, j&, arr
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- d1(myPath) = ""
- Set fso = CreateObject("Scripting.FileSystemObject")
- Do While i < d1.Count
- kr = d1.Keys
- For Each f In fso.GetFolder(kr(i)).Files
- If LCase(Right(f.Name, Len(f.Name) - InStrRev(f.Name, "."))) = "mp3" Then
- j = j + 1: d2(j) = kr(i) & "" & f.Name
- End If
- Next
- i = i + 1
- For Each fd In fso.GetFolder(kr(i - 1)).SubFolders
- d1(fd.Path) = " " & fd.Name & ""
- Next
- Loop
- ListAllFsoDic = d2.Items
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|