技術(shù) 點
- 技術(shù)
- 點
- V幣
- 點
- 積分
- 16029
|
應網(wǎng)友要求做個歷遍工作簿中所有工作表的所有單元格的過程,
但問題出現(xiàn)在最后關(guān)不掉Excel程序。查詢答案倒是正確的。
附上代碼和附件,請各位兄弟幫忙,指教。
- Private Sub Command0_Click()
- Dim Conn As New ADODB.Connection
- Dim rs As New ADODB.Recordset
- Dim i, j, k As Integer
- Dim strName, strSQL, str As String
- Dim xlApp As New Excel.Application
- Dim xlBook As Excel.Workbook
- Dim xlSheet As Excel.Worksheet
- If IsNull(Me.Text3) Then
- MsgBox "Enter then Data to Find,Please!!"
- Me.Text3.SetFocus
- Exit Sub
- End If
- strName = CurrentProject.Path & "\book1.xls"
- Set xlBook = xlApp.Workbooks.Open(strName)
- Conn.Open _
- "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False;Data Source=" _
- & strName & "; Extended Properties='Excel 8.0;HDR=Yes'"
- For k = 1 To xlBook.Sheets.Count
- strSQL = "select * from [" & xlBook.Sheets(k).Name & "$]"
- rs.Open strSQL, Conn, adOpenKeyset, adLockReadOnly
- Do While Not rs.EOF
- For i = 1 To rs.Fields.Count - 1
- If rs.Fields(i) = Me.Text3 Then
- str = xlBook.Sheets(k).Name & " " & rs.Fields(0) & i
- j = 1
- Exit Do
- End If
- Next
- rs.MoveNext
- Loop
- rs.Close
- If j = 1 Then
- Exit For
- End If
- Next
- If Len(str) <> 0 Then
- MsgBox str
- Else
- MsgBox "Nothing Was Finded"
- End If
- Conn.Close
- Set Conn = Nothing
- Set rs = Nothing
- xlBook.Close
- Set xlBook = Nothing
- xlApp.Quit
- End Sub
復制代碼 |
本帖子中包含更多資源
您需要 登錄 才可以下載或查看,沒有帳號?注冊
x
|