一次性打印多份excel表格
发布网友
发布时间:2022-03-08 06:41
我来回答
共1个回答
热心网友
时间:2022-03-08 08:11
vba,
完全可以实现.设置好格式,
统一打印,(需要编程的),
我原来用过,和你的要求差不多,
这是程序片段----------------------------写好程序,你可以放到工具栏上一个宏按钮
Sub
format()
Range("A1").Select
'更新本页数据
Selection.QueryTable.Refresh
BackgroundQuery:=False
'设置排序
Cells.Sort
Key1:=Range("J1"),
Order1:=xlDescending,
Header:=
_
xlGuess,
OrderCustom:=1,
MatchCase:=False,
Orientation:=xlTopToBottom,
_
SortMethod:=xlPinYin,
DataOption1:=xlSortNormal
Cells.Sort
Key1:=Range("I1"),
Order1:=xlAscending,
Header:=
_
xlGuess,
OrderCustom:=1,
MatchCase:=False,
Orientation:=xlTopToBottom,
_
SortMethod:=xlPinYin,
DataOption1:=xlSortNormal
'设置单元格字体字号
Cells.Font.Name
=
"微软雅黑"
Cells.Font.Size
=
8
'设置表格行高和列宽
Cells.RowHeight
=
13
Columns("A:A").ColumnWidth
=
7
Columns("B:B").ColumnWidth
=
10
Columns("C:C").ColumnWidth
=
11
Columns("D:D").ColumnWidth
=
18
Columns("E:E").ColumnWidth
=
12
Columns("F:F").ColumnWidth
=
12
Columns("G:G").ColumnWidth
=
6
Columns("H:H").ColumnWidth
=
6
Columns("I:I").ColumnWidth
=
6
Columns("J:J").ColumnWidth
=
6
Columns("K:K").ColumnWidth
=
6
Columns("L:L").ColumnWidth
=
20
'
ActiveWorkbook.SaveEnd
Sub
Sub
Printallsheet()
'打印全部
ok
=
MsgBox("您点击了直接打印封面按钮,所有部门明细表正在准备打印!"
&
Chr(13)
&
Chr(13)
&
"您确认是否打印?",
vbYesNo,
"直接打印警告!")
If
ok
=
vbYes
Then
printpage
=
0
For
n
=
1
To
4
Windows("ZCMX00"
&
CStr(n)
&
".xls").Activate
'打开该目录下的xls文件
For
i
=
1
To
Sheets.Count
'遍历工作表,打印
Sheets(i).PrintOut
Copies:=1,
Collate:=True
printpage
=
printpage
+
ExecuteExcel4Macro("GET.DOCUMENT(50)")
Next
Next
End
If
MsgBox
("共有
"
&
printpage
&
"
页打印")
'统计打印
End
Sub