|
caimh 发表于 2012-6-16 15:12 ![](static/image/common/back.gif)
VB版2的方法能不能让生成工资条之间用分页符隔开?如下图: - Sub Macro1()
- Dim Datasource
- Dim i, n, m, col As Integer
- Sheets("工资条").Select
- Cells.Clear
- ActiveWindow.View = xlNormalView
- Sheets("工资表").Select
- Set Datasource = Application.InputBox(prompt:="请选择要生成工资条的区域:", Type:=8)
- Application.ScreenUpdating = False
- col = Datasource.Columns.Count
- AddressAll = Datasource.Address
- ActiveWorkbook.ActiveSheet.Range(AddressAll).Select
- Selection.Copy
- Sheets("工资条").Select
- Range("A1").Select
- ActiveSheet.Paste
- n = ActiveSheet.Range("A65535").End(xlUp).Row
- For i = n To 3 Step -1
- ActiveCell.Rows("1:1").EntireRow.Select
- Selection.Copy
- ActiveSheet.Rows(i & ":" & i).EntireRow.Select
- Selection.Insert Shift:=xlDown
- Next i
- n = ActiveSheet.Range("A65535").End(xlUp).Row
- For i = n To 2 Step -2
- ActiveSheet.Rows(i - 1 & ":" & i).EntireRow.Select
- Selection.Insert Shift:=xlDown
- Selection.ClearFormats
- Next i
- n = ActiveSheet.Range("A65535").End(xlUp).Row
- ActiveWindow.View = xlPageBreakPreview
- For i = 1 To n / 4
- ActiveSheet.Range(Cells(i * 4 - 1, 1), Cells(i * 4, col)).Select
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .Weight = xlMedium
- End With
- With Selection.Borders(xlInsideVertical)
- .LineStyle = xlDash
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlDash
- .Weight = xlThin
- End With
- Cells(i * 4 + 1, 1).EntireRow.Select
- ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
- Next i
- 'ActiveSheet.Rows("1:1").Delete
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|