VB弹出打开对话框,选择文件
有这样一个思路,form1里有个command1,点击它就弹出一个“打开”对话框,像图那样的一个对话框,然后从电脑中选择我需要的excel文件,源代码怎样写?PS:如果在...
有这样一个思路,form1里有个command1,点击它就弹出一个“打开”对话框,像图那样的一个对话框,然后从电脑中选择我需要的excel文件,源代码怎样写?
PS:如果在command1里直接写打开某路径下的excel文件方式我会,现在需要的是有个“打开”对话框!提供示例追加分数!
怎么图片没传上来么? 展开
PS:如果在command1里直接写打开某路径下的excel文件方式我会,现在需要的是有个“打开”对话框!提供示例追加分数!
怎么图片没传上来么? 展开
2个回答
展开全部
'添加一个CommonDialog控件
'通用声明
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOW = 5
'按钮事件
Private Sub Command1_Click()
On Error GoTo userCanceled
With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
.Filter = "excel文件(*.xls)|*.xls"
.ShowOpen
ShellExecute Me.hwnd, "open", .FileName, "", "", SW_SHOW
End With
userCanceled:
End Sub
'通用声明
Private Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOW = 5
'按钮事件
Private Sub Command1_Click()
On Error GoTo userCanceled
With CommonDialog1
.CancelError = True
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
.Filter = "excel文件(*.xls)|*.xls"
.ShowOpen
ShellExecute Me.hwnd, "open", .FileName, "", "", SW_SHOW
End With
userCanceled:
End Sub
更多追问追答
追问
可不可以添加一行代码,使打开的excel为隐藏的?
追答
是更改excel文件的属性为隐藏,还是打开的excel窗口为隐藏的?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询