- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
5#
發表於 2011-5-10 14:54
| 只看該作者
回復 4# mark15jill - Private Sub 查詢()
- Dim Text$, File$, TheSh As Object, Sh As Worksheet, Rng As Range, RngAddress$
- With ThisWorkbook '程式碼置於查詢總表.xls
- Set TheSh = .Sheets("查詢")
- TheSh.UsedRange.Offset(2).Clear
- File = Dir(.Path & "\*年度*.xls")
- Do While File <> ""
- With Workbooks.Open(.Path & "\" & File)
- For Each Sh In .Sheets
- Set Rng = Sh.Range("e:e").Find(TheSh.TextBox1, LookAt:=xlWhole)
- If Not Rng Is Nothing Then
- RngAddress = Rng.Address
- With TheSh.Range("C" & Rows.Count).End(xlUp)
- .Offset(1, -2) = File
- .Offset(1, -1) = Sh.Name
- End With
- End If
- Do While Not Rng Is Nothing
- With TheSh.Range("C" & Rows.Count).End(xlUp)
- .Offset(1).Resize(1, 6) = Sh.Range(Sh.Cells(Rng.Row, "A"), Sh.Cells(Rng.Row, "F")).Value
- End With
- Set Rng = Sh.Range("e:e").FindNext(Rng)
- If RngAddress = Rng.Address Then Exit Do
- Loop
- Next
- .Close 0
- End With
- File = Dir
- Loop
- End With
- End Sub
- Sub 存檔() '程式碼置於查詢總表.xls
- Dim Sh As Object
- On Error Resume Next
- Set Sh = ThisWorkbook.Sheets(1)
-
- With Workbooks.Add(xlWBATWorksheet)
- Sh.UsedRange.Offset(1).Copy .Sheets(1).[A1]
- .SaveAs ThisWorkbook.Path & "\" & Sh.TextBox1
- .Close 0
- End With
- End Sub
複製代碼 |
|