Powerpoint 文件对话框问题 (VBA)
Powerpoint FileDialog box issues (VBA)
在我编写的小型 Powerpoint 应用程序中,我使用 .FileDialog 方法使用户能够 select 应用程序的目标文件。一切正常,除非用户想通过单击取消按钮或右上角的 X 来取消对话框,否则会生成错误并且执行失败。
那么,如果用户想要取消,PowerPoint 错误陷阱是什么?我尝试使用 Excel VBA 代码('On Error'、vbCancel 和 If 语句)来捕获错误,但没有成功。
有什么建议吗?
Sub ShowFileDialog()
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
[meta code] If selection = "" then exit sub
or
if vbCancel = True then exit sub
End With
End Sub
显示 returns 一个值。
Sub ShowFileDialog()
Dim dlgOpen As FileDialog`
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
If .Show Then
Dim I As Integer
For I = 1 To .SelectedItems.Count
Debug.Print .SelectedItems(I)
Next
Else
Debug.Print "User cancelled"
End If
End With
End Sub
在我编写的小型 Powerpoint 应用程序中,我使用 .FileDialog 方法使用户能够 select 应用程序的目标文件。一切正常,除非用户想通过单击取消按钮或右上角的 X 来取消对话框,否则会生成错误并且执行失败。
那么,如果用户想要取消,PowerPoint 错误陷阱是什么?我尝试使用 Excel VBA 代码('On Error'、vbCancel 和 If 语句)来捕获错误,但没有成功。
有什么建议吗?
Sub ShowFileDialog()
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
.Show
[meta code] If selection = "" then exit sub
or
if vbCancel = True then exit sub
End With
End Sub
显示 returns 一个值。
Sub ShowFileDialog()
Dim dlgOpen As FileDialog`
Set dlgOpen = Application.FileDialog(Type:=msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = True
If .Show Then
Dim I As Integer
For I = 1 To .SelectedItems.Count
Debug.Print .SelectedItems(I)
Next
Else
Debug.Print "User cancelled"
End If
End With
End Sub