请教VB高手,麻烦帮我解决一下!
我想用VB做一个查询系统,功能是在任意路径下找到该word或excel文件后打开该文件,程序代码如下:但打开文件的功能还是无法实现,请高手指点!
rivate Sub Command1_Click()
Dim SearchedPath As String
Dim SearchedFile As String
SearchedPath = "C:\"
SearchedFile = InputBox("输入要搜索的文件名" + Chr(13) + Chr(10) + "例如*.doc abc.*")
'FirstSearch = True
AllSearch SearchedPath, SearchedFile
Text1.Text = SearchedPath
End Sub
Private Sub Command2_Click()
'调用Word文档
FileName = "" '这里还没调试出来!
OLE1.SourceDoc = FileName
OLE1.Action = 1
OLE1.Action = 7
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
添加模块代码为
Public Const MAX_PATH = 260
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function FindFirstFile Lib "kernel32" Alias _
"FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias _
"FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal _
hFindFile As Long) As Long
Public Declare Function SetCurrentDirectory Lib "kernel32" Alias _
"SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Sub AllSearch(sPath As String, sFile As String)
Dim xf As WIN32_FIND_DATA
Dim ff As WIN32_FIND_DATA
Dim findhandle As Long
Dim lFindFile As Long
Dim astr As String
Dim bstr As String
lFindFile = FindFirstFile(sPath + "\" + sFile, ff)
If lFindFile > 0 Then
Do
Form1.List1.AddItem ff.cFileName
Loop Until (FindNextFile(lFindFile, ff) = 0)
FindClose lFindFile
End If
astr = sPath + "\" + "*.*"
findhandle = FindFirstFile(astr, xf)
DoEvents
Do
If xf.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY Then
If Asc(xf.cFileName) <> Asc(".") Then
bstr = sPath + "\" + Left$(xf.cFileName, InStr(xf.cFileName, Chr(0)) - 1)
AllSearch bstr, sFile
End If
End If
xf.cFileName = ""
Loop Until (FindNextFile(findhandle, xf) = 0)
FindClose findfile
End Sub