在一个VB程序中,有一个TEXT文本框和一个COMMAND1按钮,现在通过在TEXT文本框中输入EXCEL文件的部分文件名(也就是所有的文件名前8位数字,是唯一的),点击确定按钮来打开文件,文件在一个大的文件夹里面(内部有子文件夹),有一个问题就是,我的文件夹下面有很多个子文件夹,另外EXCEL表格也很多,怎么样才能提高查找打开的速度!我有一个思路,就是一般EXCEL文件名的前五位数和它所在的文件夹名称的前五位数是对应的,如果TEXT文本框中输入单号,那么先看它的前五位数,然后到相应的文件夹下去查找,这样速度就可以提上来了,但是这样应该怎么写代码,请各位帮忙,谢谢!下面是我写的代码,这样为什么打不开?Private Sub CmdOK_Click()
If TextPoNum.Text = "" Then
MsgBox "请输入你需要打开的EXCEL文件!"
Else
Dim oleExcel As Object
Dim PoNum As String
Dim a As String
Set oleExcel = CreateObject("Excel.Application")
a = Left(TextPoNum.Text, 5)
With oleExcel
With .Application.FileSearch
.NewSearch
.LookIn = "c:\新建文件夹\a&*"
.SearchSubFolders = True
.FileName = TextPoNum.Text & "*.xls"
If .Execute() > 0 Then
oleExcel.Visible = True
oleExcel.Workbooks.Open .FoundFiles(1)
Else
MsgBox "没有找到符合条件的文件."
End If
End With
End With
End If
If TextPoNum.Text = "" Then
MsgBox "请输入你需要打开的EXCEL文件!"
Else
Dim oleExcel As Object
Dim PoNum As String
Dim a As String
Set oleExcel = CreateObject("Excel.Application")
a = Left(TextPoNum.Text, 5)
With oleExcel
With .Application.FileSearch
.NewSearch
.LookIn = "c:\新建文件夹\a&*"
.SearchSubFolders = True
.FileName = TextPoNum.Text & "*.xls"
If .Execute() > 0 Then
oleExcel.Visible = True
oleExcel.Workbooks.Open .FoundFiles(1)
Else
MsgBox "没有找到符合条件的文件."
End If
End With
End With
End If
oleExcel.Visible = True
'strFilePath
Set xlbook = xls.Workbooks.Add(strFilePath)Set xlsheet = xlbook.Worksheets(1)
xlbook.Application.Visible = True
xlbook.Windows(1).Visible = True
oleExcel.Visible = True
'取得strFilePath 文件名及其路径后用红色的这句
Set xlbook = oleExcel.Workbooks.Add(strFilePath) Set xlsheet = xlbook.Worksheets(1)
xlbook.Application.Visible = True
xlbook.Windows(1).Visible = True