|
楼主 |
发表于 2016-10-11 12:45
|
显示全部楼层
本帖最后由 weiyingde 于 2016-10-11 16:10 编辑
还有个问题要请教你。
目的:机动插入当前路径里面的音视频
问题:有时弹出下标越界,有时是对象的问题。我对dir函数理解和运用不熟。估计出问题的地方是红字的部分。
本应该上传附件,可是音视频的体积大,无法直接上传,暂时又没有闲暇编辑音视频,所以直接给了代码,如若一定要附件,我稍后再上传。烦请大侠帮我一看。谢谢你。
代码如下:
Sub 插入音视频()
h = ActivePresentation.PageSetup.SlideHeight / 2
w = ActivePresentation.PageSetup.SlideWidth / 2
l = w / 4 + 10
t = h / 2
s1 = ".wmv.mp4.flv.avi.f4v"
s2 = ".mp3.wav"
s3 = ".wmv.mp4.flv.avi.f4v.mp3.wav"
s = IIf(SlideMaster.CommandButton10.Caption = "视", s1, s2)
mypath = ActivePresentation.Path & "\"
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
mn = Dir(mypath & "*.*")
Do While mn <> ""
If InStrRev(s3, Split(mns, ".")(1), 1) > 0 Then
If InStrRev(s1, Split(mns, ".")(1), 1) > 0 Then
d1(mypath & mn) = ""
Else
d2(mypath & mn) = ""
End If
mn = Dir
End If
Loop
k1 = d1.keys
k2 = d1.keys
Randomize
filnm1 = k1(Int(Rnd * d1.Count) + 1)
filnm2 = k2(Int(Rnd * d2.Count) + 1)
If s = "视" Then
For Each shp In ActivePresentation.SlideShowWindow.View.Slide.Shapes
If shp.Type = 16 Then shp.Delete
Next
Set shp = Nothing
Set sld = ActivePresentation.SlideShowWindow.View.Slide
Set shps = sld.Shapes
Set sp = shps.AddMediaObject2(FileName:=filnm1, Left:=l, Top:=t, Width:=w, Height:=h)
With sp
.AutoShapeType = Choose(Int(Rnd * 9) + 1, 6, 9, 10, 132, 13, 28, 94, 95, 96)
With .ThreeD
If sj Mod 2 = 1 Then
.SetThreeDFormat msoThreeD & (Int(Rnd * 20) + 1)
Else
.BevelTopType = 3
.BevelTopDepth = 10
.BevelBottomType = 3
.BevelBottomDepth = 6
End If
End With
With ActivePresentation.SlideShowWindow.View.Slide
.TimeLine.InteractiveSequences(1).Item(1).Delete
.TimeLine.MainSequence.AddEffect sp, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious
End With
Set seq = sld.TimeLine.MainSequence
s = seq.Count
seq(s).MoveBefore seq(1)
End With
Set sp = Nothing
Else
For Each shp In ActivePresentation.SlideShowWindow.View.Slide.Shapes '插入音频
If shp.Type = 16 Then shp.Delete
Next
Set shp = Nothing
Set sp = shps.AddMediaObject2(FileName:=filnm2, Left:=0, Top:=ActivePresentation.PageSetup.SlideHeight + 10)
With sp
With ActivePresentation.SlideShowWindow.View.Slide
.TimeLine.InteractiveSequences(1).Item(1).Delete
.TimeLine.MainSequence.AddEffect sp, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious
End With
Set seq = sld.TimeLine.MainSequence
s = seq.Count
seq(s).MoveBefore seq(1)
End With
Set sp = Nothing
End If
End Sub
|
|