我正在修改两段代码(归功于Shyam Pillai和Analyst Cave),我正在尝试使用一个对话框来选择多个音频文件,然后将这些音频文件插入每个幻灯片中,并在其中插入一些以下代码中指定的固定设置。
对话框和其他代码可以完美地工作,但是作为VBA菜鸟,我无法使它们一起工作,基本上使代码的第二部分使用出现对话框时选择的文件。我确定我缺少调用函数,但是我不知道如何获取对话框结果并将其用作代码第二部分的输入
任何指导将不胜感激
Sub SampleTest()
Dim fDialog As FileDialog, result As Integer
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
'IMPORTANT!
fDialog.AllowMultiSelect = True
'Optional FileDialog properties
fDialog.Title = "Select a file"
fDialog.InitialFileName = "C:\"
'Optional: Add filters
fDialog.Filters.Clear
fDialog.Filters.Add "Excel files", "*.xlsx"
fDialog.Filters.Add "All files", "*.*"
'Show the dialog. -1 means success!
If fDialog.Show = -1 Then
For Each it In fDialog.SelectedItems
Debug.Print it
Next it
End If
End Sub
Sub InsertAudio(Track As String, oSlide As Slide)
Dim oShp As Shape
Dim oEffect As Effect
'Add the audio shape
Set oShp = oSlide.Shapes.AddMediaObject2(Track, True, False, 10, 10)
'Set audio to play automatically
Set oEffect = oSlide.TimeLine.MainSequence.AddEffect(oShp, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious)
oEffect.MoveTo 1
'Hide during slide show
With oEffect
.EffectInformation.PlaySettings.HideWhileNotPlaying = True
End With
End Sub