示例
Sub DisplayOpenFileDialog()
Dim openFile As New System.Windows.Forms.OpenFileDialog()
openFile.DefaultExt = "doc"
openFile.Filter = "Word documents (*.doc)|*.doc"
openFile.ShowDialog()
If openFile.FileNames.Length > 0 Then
Dim filename As String
For Each filename In openFile.FileNames
' Insert code here to process the files.
Next
End If
End Sub
编译代码
如果将此代码放置于 Windows 窗体的某一方法中,并且如果还在名为 openFile 的窗体上具有 OpenFileDialog 控件,则可能会产生意外的结果。此方法创建名为 openFile 的 OpenFileDialog 的新实例。
Filter 属性要求搜索字符串位于管道符号 ( | ) 后。
本文介绍了一个使用VBA实现的文件打开对话框示例代码,展示了如何设置默认扩展名、过滤条件及处理所选文件的方法。该示例适用于需要在Windows环境中通过VBA读取特定类型文件的应用场景。
2569

被折叠的 条评论
为什么被折叠?



