|
用一个工作簿做跳板,应该算是比较简单的做法了。点击“农户信息表”中的“拆分新表”按钮,即批量生成新表。
在这个应用中,其实可以充分利用原有的查询代码,遍历身份证号后将查询结果生成新工作簿。这样代码短小,运行速度也比较快。
附件已修正:
批量拆分表.rar
(38.49 KB, 下载次数: 34)
- Private Sub CommandButton1_Click()
- Dim str$, stg$, rng As Range
- Dim Sh As Worksheet, Sht As Worksheet
- Dim wk$
- Set Sh = ThisWorkbook.Sheets("附件5.1")
- Set Sht = ThisWorkbook.Sheets("附件5.2")
- wk = ThisWorkbook.Path & "\Model.xls"
-
- For Each rng In Range("B3", [B65536].End(3))
- str = rng
- stg = rng.Offset(, 1)
- Sh.[A2] = str
- Workbooks.Open Filename:=wk
- With ActiveWorkbook
- .Sheets("1").[A3].Resize(34, 25).Value = Sh.[A7].Resize(34, 25).Value
- .Sheets("2").[A4].Resize(33, 11).Value = Sht.[A8].Resize(33, 11).Value
- .SaveAs Filename:=ThisWorkbook.Path & "" & stg & ".xls"
- .Close Save = True
- End With
- Next
- End Sub
复制代码
[ 本帖最后由 alzeng 于 2009-7-18 14:55 编辑 ] |
|