|
- Sub 根据分割线拆分成不同工作薄() 'bajifeng
- 'http://club.excelhome.net/thread-1254084-1-1.html
- Dim r(1 To 100, 1 To 2)
- Set wbo = ActiveWorkbook
- s = Array("-------", "INVOICE #")
- pth = ThisWorkbook.Path & ""
- For j = 0 To UBound(s)
- n = 0
- Set c = Cells.Find(what:=s(j), LookIn:=xlValues, lookat:=xlPart)
- If Not c Is Nothing Then
- addr = c.Address
- Do
- n = n + 1
- r(n, j + 1) = c.Row
- Set c = Cells.FindNext(c)
- Loop While addr <> c.Address
- End If
- Next
- cn = 38
- ReDim cw(1 To cn)
- For i = 1 To cn
- cw(i) = Columns(i).ColumnWidth
- Next
- For i = 1 To n
- fnm = wbo.Sheets(1).Cells(r(i, 2), "w") & ".xlsx"
- If i = 1 Then
- sr = 1
- Else
- sr = r(i - 1, 1) + 1
- End If
- er = r(i, 1) '如果不要虚线设置为 r(i, 1) - 1
- wbo.Sheets(1).Range(Cells(sr, "a"), Cells(er, "al")).Copy
- Set wbn = Workbooks.Add
- ActiveSheet.[a1].PasteSpecial
- For k = 1 To cn
- Columns(k).ColumnWidth = cw(k)
- Next
- ActiveWindow.DisplayGridlines = False
- wbn.SaveAs pth & fnm
- wbn.Close False
- Next
- End Sub
复制代码 |
|