VB如何实现一个按钮,点击按钮之后就能够浏览电脑中的文件夹,当选中文件夹之后显示该文件下的所有Excel文

件,当选中想要打开的文件之后就能够打开。跪求代码,在线等待,非常感谢。。... 件,当选中想要打开的文件之后就能够打开。跪求代码,在线等待,非常感谢。。 展开
 我来答
xlzzc
2012-05-01 · TA获得超过7301个赞
知道大有可为答主
回答量:4205
采纳率:50%
帮助的人:1424万
展开全部

VB2010的可以吗? “能够浏览电脑中的文件夹”你指在什么 地方什么组件内浏览?”当选中文件夹之后”这里的“选中”是什么操作? 

...............

vb6的:

Private Sub Command1_Click()

    With CommonDialog1

        .DialogTitle = "打开Ecxel文件"

        .Filter = "EXCEL文件|*.xls;*.xlsx"

    .ShowOpen

    

    End With

End Sub

追问
其实我是想做一个类似于Word或者Exel的打开文件的窗口,能够选择自己所要打开的word或者Excel文件。
二白Q0
2012-05-02 · TA获得超过2413个赞
知道大有可为答主
回答量:990
采纳率:0%
帮助的人:1088万
展开全部
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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 OFN_HIDEREADONLY = &H4
Const OFN_PATHMUSTEXIST = &H800
Const OFN_FILEMUSTEXIST = &H1000

Private Sub Command1_Click()
Dim ofn As OPENFILENAME
Dim rtn As String
Dim sFile As String

ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hwnd
ofn.flags = OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
ofn.lpstrFile = String(255, 0)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = String(255, 0)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path & "\"
ofn.lpstrFilter = "excel工作簿(*.xls)" & Chr$(0) & "*.xls;" & Chr$(0) & Chr$(0) '打开的文件类型
ofn.nFilterIndex = 1
ofn.lpstrTitle = "打开文件"
rtn = GetOpenFileName(ofn)
If rtn > 0 Then
sFile = Left(ofn.lpstrFile, InStr(ofn.lpstrFile, Chr(0)) - 1)
ShellExecute Me.hwnd, "open", sFile, vbNullString, vbNullString, 1
End If
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式