无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 590|回复: 59
打印 上一主题 下一主题

[求助] excel打印格式设置求助

  [复制链接]
跳转到指定楼层
1#
发表于 前天 11:37 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
每月都要打印不同的excel工作簿,工作簿格式相同,只是单元格数据不同,每次手动设置工作表格式,都是重复的劳动,怎么操作一下,工作簿自动调整行高列宽等动作,要启用宏吗,我不会,知道这里高手多,给指点一下,谢谢
2#
 楼主| 发表于 前天 11:38 | 只看该作者
怎么启用宏,我也不会,高手给说一下。
回复

使用道具 举报

3#
发表于 前天 11:43 | 只看该作者
先弄好格式,给填数据的。
回复

使用道具 举报

4#
 楼主| 发表于 前天 11:48 | 只看该作者
有没有更好的办法,数据是从报表网站导下来的,只是调整格式,打印一下
回复

使用道具 举报

5#
发表于 前天 12:00 | 只看该作者
让有模板的excel读取报表网站下载下来的数据,加载到打印的模板文件,可以借助PowerQuery等等,也可以简单的从文件导入然后做排版。
回复

使用道具 举报

6#
发表于 前天 12:09 | 只看该作者
自已录制一个宏,另存为启用宏的工作簿xlsm
下次打开,按ALT+F8运行宏

点评

不会,给详细说一下呗,谢谢您  详情 回复 发表于 前天 12:13
回复

使用道具 举报

7#
发表于 前天 12:12 | 只看该作者
外部可用JS
_Sheet.Columns("C:D").ColumnWidth=20;        //列宽20
_Sheet.Columns("A:B").AutoFit;        //列宽自适应
_Sheet.Rows(5).RowHeight=30;        //行高30
_Sheet.Rows("6:7").AutoFit;        //行高自适应

点评

要设置的很多,比如:列宽有1.88,有7.5的,行高:不同的工作表也不一样,且行高也不同,有22的,有18的,还有字体,打印区域,打印标题等设置  详情 回复 发表于 前天 12:26
回复

使用道具 举报

8#
 楼主| 发表于 前天 12:13 | 只看该作者
ohte 发表于 2026-2-4 12:09
自已录制一个宏,另存为启用宏的工作簿xlsm
下次打开,按ALT+F8运行宏

不会,给详细说一下呗,谢谢您

点评

宏录制使用方法 宏录制是自动化重复性任务的有效工具,特别适用于 Microsoft Excel 等支持 VBA(Visual Basic for Applications)的应用程序。以下是使用宏录制的详细步骤: 1.启用开发工具选项卡 打开 Exc  详情 回复 发表于 前天 12:42
回复

使用道具 举报

9#
 楼主| 发表于 前天 12:26 | 只看该作者
cutebe 发表于 2026-2-4 12:12
外部可用JS
_Sheet.Columns("C:D").ColumnWidth=20;        //列宽20
_Sheet.Columns("A:B").AutoFit;        //列宽自 ...

要设置的很多,比如:列宽有1.88,有7.5的,行高:不同的工作表也不一样,且行高也不同,有22的,有18的,还有字体,打印区域,打印标题等设置
回复

使用道具 举报

10#
发表于 前天 12:42 | 只看该作者
本帖最后由 ohte 于 2026-2-4 12:48 编辑
zhoubin 发表于 2026-2-4 12:13
不会,给详细说一下呗,谢谢您

宏录制使用方法视频教程:bilibili.com/video/av947645936/

宏录制是自动化重复性任务的有效工具,特别适用于 Microsoft Excel 等支持 VBA(Visual Basic for Applications)的应用程序。以下是使用宏录制的详细步骤:

1.启用开发工具选项卡

打开 Excel,点击 文件 > 选项 > 自定义功能区。

在右侧的主选项卡列表中勾选 开发工具,然后点击 确定。

2.录制宏

在 开发工具 选项卡中,点击 录制宏。 输入宏的名称(首字符必须为字母,不能包含空格)。 可选择分配快捷键(建议使用 Ctrl + Shift 组合键以避免覆盖默认快捷键)。 选择保存位置(如“此工作簿”)。 可在说明框中输入宏的用途描述(可选)。

点击 确定 开始录制。

执行需要自动化的操作,例如格式化单元格、输入数据或应用公式。

完成后,点击 停止录制。

3.运行宏

使用快捷键:如果在录制时设置了快捷键,可直接按下运行。

使用宏对话框: 点击 开发工具 > 宏 或按 Alt + F8。 选择要运行的宏并点击 运行。



4.查看和编辑代码

按 Alt + F11 打开 VBA 编辑器。

在左侧项目窗口中找到对应模块,双击查看生成的代码。

可根据需要修改代码以实现更复杂的功能。

5.注意事项

宏无法撤销操作,建议在副本上测试运行。

确保启用宏安全性设置,并仅运行来自可信来源的宏。

通过以上步骤,您可以轻松录制和管理宏,从而提高工作效率。

点评

助人为乐  发表于 前天 17:35
感谢,我试一下,谢谢  详情 回复 发表于 前天 14:29

评分

参与人数 1无忧币 +5 收起 理由
yyz2191958 + 5

查看全部评分

回复

使用道具 举报

11#
发表于 前天 13:06 | 只看该作者
如果打印的格式都是固定的。那最简单的就是做好这一版然后锁定格式,最后把下载数据内容复制仅数值进去就可以了。
回复

使用道具 举报

12#
发表于 前天 13:11 | 只看该作者
纯路过~顶起来!
回复

使用道具 举报

13#
发表于 前天 13:15 来自手机 | 只看该作者
你要是工作簿中含有多个表格,且表格的格式都是一样的,只是数据不同?这样的话,多简单,你自己要在工作簿中按crlt键,鼠标指向sheet1,向右拖移,就会生成一个格式相同的sheet2表格,清空其中数据,重新填写新的数据不就好了?
回复

使用道具 举报

14#
发表于 前天 13:16 来自手机 | 只看该作者
写宏命令,也可以。有点烦。
回复

使用道具 举报

15#
发表于 前天 13:37 来自手机 | 只看该作者
不是复制一个,改改数据不就好了,为什么一直要调整。
回复

使用道具 举报

16#
发表于 前天 13:50 | 只看该作者
看看
回复

使用道具 举报

17#
 楼主| 发表于 前天 14:29 | 只看该作者
ohte 发表于 2026-2-4 12:42
宏录制使用方法视频教程:bilibili.com/video/av947645936/

宏录制是自动化重复性任务的有效工具,特 ...

感谢,我试一下,谢谢
回复

使用道具 举报

18#
发表于 前天 15:18 | 只看该作者
学习一下
回复

使用道具 举报

19#
 楼主| 发表于 前天 15:50 | 只看该作者
本帖最后由 zhoubin 于 2026-2-5 07:59 编辑

录了一段宏,竟然用不了,提示:编译错误:参数不可选,大佬帮我看看哪里错了,谢谢

打印设置 - 宏.txt

131.86 KB, 下载次数: 7, 下载积分: 无忧币 -2

回复

使用道具 举报

20#
发表于 前天 16:00 | 只看该作者
我觉得吧,干活的速度不能太快,毕竟总有干不完的活...


二○二六年二月四日
回复

使用道具 举报

21#
发表于 前天 16:08 | 只看该作者
做一个固定的模板就好了。
回复

使用道具 举报

22#
发表于 前天 16:35 | 只看该作者
zhoubin 发表于 2026-2-4 12:26
要设置的很多,比如:列宽有1.88,有7.5的,行高:不同的工作表也不一样,且行高也不同,有22的,有18的 ...
  1. //设置表格格式.JS
  2. var xlsFile=WScript.Arguments(0);        //拖入表格文件

  3. var XlsApp = new ActiveXObject("Excel.Application");        //创建表格程序对象
  4. var _Books = XlsApp.Workbooks.open(xlsFile);        //打开表格文件(簿)
  5. var _Sheet = _Books.Worksheets(1);        //工作表

  6. XlsApp.Visible = 1;        //显示表格程序

  7. _Sheet.Columns(3).ColumnWidth=1.88;        //列宽1.88
  8. _Sheet.Columns(4).ColumnWidth=7.5;        //列宽7.5
  9. _Sheet.Columns("A:B").AutoFit;        //列宽自适应
  10. _Sheet.Rows(1).RowHeight=22;        //行高22
  11. _Sheet.Rows(2).RowHeight=18;        //行高18
  12. _Sheet.Rows("5:8").AutoFit;        //行高自适应

  13. _Sheet.UsedRange.Font.Name='宋体';        //字体

  14. _Sheet.PageSetup.PrintTitleRows = "$1:$2";        //顶端标题行
  15. _Sheet.PageSetup.PrintTitleColumns = "$A:$E";        //左端标题列

  16. _Sheet.PageSetup.PrintArea = _Sheet.Range("A1:E35").Address;        //打印区域
复制代码

点评

有一excel工作簿:决算.xls,工作簿里有15个工作表[attachimg]571685[/attachimg], 000工作表:打印区域选定为:A1:B17,无填充颜色;纵向打印;打印页边距:上2.5、下2.5、左1.4、右1.3。003工作表:打印区域选定  详情 回复 发表于 前天 21:52
好人  发表于 前天 17:37

评分

参与人数 1无忧币 +5 收起 理由
yyz2191958 + 5

查看全部评分

回复

使用道具 举报

23#
发表于 前天 21:21 | 只看该作者
这不就是先空表格搞好当模版,每次复制数据就行了吗?
回复

使用道具 举报

24#
 楼主| 发表于 前天 21:52 | 只看该作者

有一excel工作簿:决算.xls,工作簿里有15个工作表 ,
000工作表:打印区域选定为:A1:B17,无填充颜色;纵向打印;打印页边距:上2.5、下2.5、左1.4、右1.3
003工作表:打印区域选定为:A1:BF80,无填充颜色;横向打印;打印页边距:上1.9、下1.8、左1、右0.4CD列:列宽1.88EF列:列宽7.5G列至AR列:列宽1.88ASAT列:列宽7.5AU列至BE列:列宽1.88BF列:列宽9.86,其余列保持原列宽,不做调整;替换工作簿里:金额单位:?$为金额单位:万元;设置A3: BF80,宋体8号字;46行,行高调整为147行,行高调整为69880行,行高调整为14,其余行高保持原行高,不做调整;打印:将所有列调整为一页;打印顶端标题行13行($1:$3)。
其余002表以后,不再赘述. . . 谢谢

点评

把决算.xls拖入JS文件图标上  详情 回复 发表于 昨天 09:33
回复

使用道具 举报

25#
发表于 前天 21:53 | 只看该作者
围观
回复

使用道具 举报

26#
发表于 前天 22:13 | 只看该作者
录个宏最省事了。

感谢各位高手!
回复

使用道具 举报

27#
发表于 前天 22:17 | 只看该作者
看看这个。

日常工作中,有很多时候需要将Excel文件中的内容逐个粘贴到软件/网页中(填表操作),需要不停的复制-粘贴,该软件可以省略打开Excel文件和复制的操作,点击相应的复制按钮即可将所需数据复制到剪切板中。
操作要求:
1.需要在软件同级目录放置以_build.xlsx结尾的excle文件,若无法确定数据是否合适,请将所需数据粘贴到测试表格中运行,表格第一行为标题,标题会被直接读取到按钮标题中;
2.运行后界面“上一条”和“下一条”会逐行显示数据,复制:...按钮会将当前行的数据复制到剪贴板中,使用时直接粘贴即可。
注意:
1.该软件暂时还未适配xls文件,使用时请将文件另存为xlsx格式的文件;
2.软件退出后会将当前读取行数保存到用户目录下,不喜欢乱七八糟配置文件的请另寻高明。
软件及测试文件下载链接:
文件名称:万能表格复制助手 v0.6.zip
百度网盘分享链接: https://pan.baidu.com/s/1FEakoE4WFM5NxODs-UTkPQ
提取码: u3q5
回复

使用道具 举报

28#
发表于 昨天 08:37 来自手机 | 只看该作者
Option Explicit  Sub MonthPrint_Optimized()     ' MonthPrint 优化版宏     ' 打印月年报 - 修复和优化版本          On Error GoTo ErrorHandler          ' 定义工作表数组     Dim sheetNames As Variant     sheetNames = Array("000", "003", "002", "100", "101", "102", "104", "105", _                        "106", "107", "108", "109", "900", "103", "001")          Dim startTime As Double     startTime = Timer          Application.ScreenUpdating = False     Application.Calculation = xlCalculationManual     Application.DisplayAlerts = False          Dim ws As Worksheet     Dim sheetName As Variant          ' 批量处理所有工作表     For Each sheetName In sheetNames         On Error Resume Next         Set ws = ThisWorkbook.Sheets(CStr(sheetName))         On Error GoTo ErrorHandler                  If Not ws Is Nothing Then             ' 应用基础打印设置             ApplyBasePrintSettings ws                          ' 根据工作表名称应用特定设置             Select Case CStr(sheetName)                 Case "000"                     ApplySheet000Settings ws                 Case "003"                     ApplySheet003Settings ws                 Case "002"                     ApplySheet002Settings ws                 Case "100", "101", "102", "104", "105", "106", "107"                     ApplyGeneralSheetSettings ws                 Case "108", "109", "900", "103", "001"                     ApplyGeneralSheetSettings ws                     ' 可以为每个表添加特定设置                     If CStr(sheetName) = "001" Then                         ApplySheet001Settings ws                     End If             End Select                          Set ws = Nothing         End If     Next sheetName      CleanUp:     Application.ScreenUpdating = True     Application.Calculation = xlCalculationAutomatic     Application.DisplayAlerts = True          Dim elapsedTime As Double     elapsedTime = Timer - startTime     MsgBox "打印设置完成!耗时: " & Format(elapsedTime, "0.00") & "秒", vbInformation          Exit Sub  ErrorHandler:     MsgBox "错误发生: " & Err.Description & vbCrLf & _            "错误号: " & Err.Number & vbCrLf & _            "工作表: " & IIf(ws Is Nothing, "N/A", ws.Name), vbCritical     Resume CleanUp End Sub  ' 基础打印设置子程序 Private Sub ApplyBasePrintSettings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         ' 页边距设置         .LeftMargin = Application.InchesToPoints(0.75)         .RightMargin = Application.InchesToPoints(0.75)         .TopMargin = Application.InchesToPoints(1)         .BottomMargin = Application.InchesToPoints(1)         .HeaderMargin = Application.InchesToPoints(0.5)         .FooterMargin = Application.InchesToPoints(0.5)                  ' 基本打印选项         .PrintHeadings = False         .PrintGridlines = False         .PrintComments = xlPrintNoComments         .CenterHorizontally = False         .CenterVertically = False         .Draft = False         .PaperSize = xlPaperA4         .FirstPageNumber = xlAutomatic         .Order = xlDownThenOver         .BlackAndWhite = False         .Zoom = False         .PrintErrors = xlPrintErrorsDisplayed         .OddAndEvenPagesHeaderFooter = False         .DifferentFirstPageHeaderFooter = False         .ScaleWithDocHeaderFooter = True         .AlignMarginsHeaderFooter = False                  ' 清空页眉页脚         .LeftHeader = ""         .CenterHeader = ""         .RightHeader = ""         .LeftFooter = ""         .CenterFooter = ""         .RightFooter = ""                  ' 偶数页页眉页脚         .EvenPage.LeftHeader.Text = ""         .EvenPage.CenterHeader.Text = ""         .EvenPage.RightHeader.Text = ""         .EvenPage.LeftFooter.Text = ""         .EvenPage.CenterFooter.Text = ""         .EvenPage.RightFooter.Text = ""                  ' 首页页眉页脚         .FirstPage.LeftHeader.Text = ""         .FirstPage.CenterHeader.Text = ""         .FirstPage.RightHeader.Text = ""         .FirstPage.LeftFooter.Text = ""         .FirstPage.CenterFooter.Text = ""         .FirstPage.RightFooter.Text = ""     End With          Application.PrintCommunication = True End Sub  ' 工作表000的特定设置 Private Sub ApplySheet000Settings(ws As Worksheet)     With ws.PageSetup         .Orientation = xlPortrait         .FitToPagesWide = 1         .FitToPagesTall = 0     End With End Sub  ' 工作表003的特定设置 Private Sub ApplySheet003Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         ' 设置为横向         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False                  ' 打印区域         .PrintArea = "$A$1:$BF$80"         .PrintTitleRows = "$1:$8"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.669)         .BottomMargin = Application.InchesToPoints(0.591)     End With          Application.PrintCommunication = True          ' 设置列宽和行高     With ws         ' 设置列宽         .Columns("C:BF").ColumnWidth = 1.88         .Columns("E:E").ColumnWidth = 7.5         .Columns("F:F").ColumnWidth = 7.5         .Columns("AS:AS").ColumnWidth = 7.5         .Columns("AT:AT").ColumnWidth = 7.5         .Columns("BF:BF").ColumnWidth = 11.29                  ' 设置行高         .Rows("1:1").RowHeight = 10.5         .Rows("2:2").RowHeight = 27         .Rows("3:3").RowHeight = 44.25         .Rows("7:7").RowHeight = 81         .Rows("8:80").RowHeight = 18                  ' 设置字体         .Range("C10:BF80").Font.Name = "宋体"         .Range("C10:BF80").Font.Size = 9         .Range("A4:BF80").Font.Size = 10                  ' 替换文本         .Range("AT3").Replace What:="金额单位:?$", Replacement:="金额单位:万元", LookAt:=xlPart         .Range("BF3").Value = "表号:003" & Chr(10) & "金额单位:万元"     End With End Sub  ' 工作表002的特定设置 Private Sub ApplySheet002Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False         .PrintTitleRows = "$1:$4"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.709)         .BottomMargin = Application.InchesToPoints(0.63)     End With          Application.PrintCommunication = True          With ws         ' 设置行高         .Rows("1:1").RowHeight = 17.25         .Rows("2:2").RowHeight = 20.25         .Rows("3:3").RowHeight = 26.25         .Rows("4:75").RowHeight = 14                  ' 设置列宽         .Columns("F:F").ColumnWidth = 47.57                  ' 设置字体         .Range("F31,F69,F70").Font.Name = "宋体"         .Range("F31,F69,F70").Font.Size = 6     End With End Sub  ' 工作表001的特定设置 Private Sub ApplySheet001Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False         .PrintTitleRows = "$1:$8"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.984)         .BottomMargin = Application.InchesToPoints(0.827)     End With          Application.PrintCommunication = True          With ws         ' 设置列宽         .Columns("C:AF").ColumnWidth = 9     End With End Sub  ' 通用工作表设置 Private Sub ApplyGeneralSheetSettings(ws As Worksheet)     ' 默认设置为横向     With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False     End With          ' 替换所有工作表中的"金额单位:?$"     On Error Resume Next     ws.Cells.Replace What:="金额单位:?$", Replacement:="金额单位:万元", LookAt:=xlPart     On Error GoTo 0 End Sub  ' 快捷打印宏 Sub QuickPrintAll()     ' 直接打印所有配置好的工作表     On Error GoTo PrintError          Application.ScreenUpdating = False          Dim sheetNames As Variant     sheetNames = Array("000", "003", "002", "100", "101", "102", "104", "105", _                        "106", "107", "108", "109", "900", "103", "001")          Dim wsNames() As String     ReDim wsNames(0 To UBound(sheetNames))          Dim i As Long     For i = 0 To UBound(sheetNames)         wsNames(i) = CStr(sheetNames(i))     Next i          ' 选择并打印所有工作表     ThisWorkbook.Sheets(wsNames).Select     ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True      CleanUp:     Application.ScreenUpdating = True     Exit Sub      PrintError:     MsgBox "打印错误: " & Err.Description, vbExclamation     Resume CleanUp End Sub  ' 恢复默认设置(可选) Sub ResetPrintSettings()     Dim ws As Worksheet     Dim response As VbMsgBoxResult          response = MsgBox("确定要重置所有工作表的打印设置吗?", vbYesNo + vbQuestion, "确认重置")          If response = vbYes Then         Application.ScreenUpdating = False                  For Each ws In ThisWorkbook.Worksheets             With ws.PageSetup                 ' 恢复默认设置                 .LeftHeader = ""                 .CenterHeader = ""                 .RightHeader = ""                 .LeftFooter = ""                 .CenterFooter = ""                 .RightFooter = ""                 .LeftMargin = Application.InchesToPoints(0.75)                 .RightMargin = Application.InchesToPoints(0.75)                 .TopMargin = Application.InchesToPoints(1)                 .BottomMargin = Application.InchesToPoints(1)                 .HeaderMargin = Application.InchesToPoints(0.5)                 .FooterMargin = Application.InchesToPoints(0.5)                 .PrintHeadings = False                 .PrintGridlines = False                 .CenterHorizontally = False                 .CenterVertically = False                 .Orientation = xlPortrait                 .PaperSize = xlPaperA4                 .FirstPageNumber = xlAutomatic                 .Zoom = 100                 .PrintArea = ""                 .PrintTitleRows = ""                 .PrintTitleColumns = ""   
回复

使用道具 举报

29#
发表于 昨天 08:39 来自手机 | 只看该作者
Option Explicit  Sub MonthPrint_Optimized()     ' MonthPrint 优化版宏     ' 打印月年报 - 修复和优化版本          On Error GoTo ErrorHandler          ' 定义工作表数组     Dim sheetNames As Variant     sheetNames = Array("000", "003", "002", "100", "101", "102", "104", "105", _                        "106", "107", "108", "109", "900", "103", "001")          Dim startTime As Double     startTime = Timer          Application.ScreenUpdating = False     Application.Calculation = xlCalculationManual     Application.DisplayAlerts = False          Dim ws As Worksheet     Dim sheetName As Variant          ' 批量处理所有工作表     For Each sheetName In sheetNames         On Error Resume Next         Set ws = ThisWorkbook.Sheets(CStr(sheetName))         On Error GoTo ErrorHandler                  If Not ws Is Nothing Then             ' 应用基础打印设置             ApplyBasePrintSettings ws                          ' 根据工作表名称应用特定设置             Select Case CStr(sheetName)                 Case "000"                     ApplySheet000Settings ws                 Case "003"                     ApplySheet003Settings ws                 Case "002"                     ApplySheet002Settings ws                 Case "100", "101", "102", "104", "105", "106", "107"                     ApplyGeneralSheetSettings ws                 Case "108", "109", "900", "103", "001"                     ApplyGeneralSheetSettings ws                     ' 可以为每个表添加特定设置                     If CStr(sheetName) = "001" Then                         ApplySheet001Settings ws                     End If             End Select                          Set ws = Nothing         End If     Next sheetName      CleanUp:     Application.ScreenUpdating = True     Application.Calculation = xlCalculationAutomatic     Application.DisplayAlerts = True          Dim elapsedTime As Double     elapsedTime = Timer - startTime     MsgBox "打印设置完成!耗时: " & Format(elapsedTime, "0.00") & "秒", vbInformation          Exit Sub  ErrorHandler:     MsgBox "错误发生: " & Err.Description & vbCrLf & _            "错误号: " & Err.Number & vbCrLf & _            "工作表: " & IIf(ws Is Nothing, "N/A", ws.Name), vbCritical     Resume CleanUp End Sub  ' 基础打印设置子程序 Private Sub ApplyBasePrintSettings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         ' 页边距设置         .LeftMargin = Application.InchesToPoints(0.75)         .RightMargin = Application.InchesToPoints(0.75)         .TopMargin = Application.InchesToPoints(1)         .BottomMargin = Application.InchesToPoints(1)         .HeaderMargin = Application.InchesToPoints(0.5)         .FooterMargin = Application.InchesToPoints(0.5)                  ' 基本打印选项         .PrintHeadings = False         .PrintGridlines = False         .PrintComments = xlPrintNoComments         .CenterHorizontally = False         .CenterVertically = False         .Draft = False         .PaperSize = xlPaperA4         .FirstPageNumber = xlAutomatic         .Order = xlDownThenOver         .BlackAndWhite = False         .Zoom = False         .PrintErrors = xlPrintErrorsDisplayed         .OddAndEvenPagesHeaderFooter = False         .DifferentFirstPageHeaderFooter = False         .ScaleWithDocHeaderFooter = True         .AlignMarginsHeaderFooter = False                  ' 清空页眉页脚         .LeftHeader = ""         .CenterHeader = ""         .RightHeader = ""         .LeftFooter = ""         .CenterFooter = ""         .RightFooter = ""                  ' 偶数页页眉页脚         .EvenPage.LeftHeader.Text = ""         .EvenPage.CenterHeader.Text = ""         .EvenPage.RightHeader.Text = ""         .EvenPage.LeftFooter.Text = ""         .EvenPage.CenterFooter.Text = ""         .EvenPage.RightFooter.Text = ""                  ' 首页页眉页脚         .FirstPage.LeftHeader.Text = ""         .FirstPage.CenterHeader.Text = ""         .FirstPage.RightHeader.Text = ""         .FirstPage.LeftFooter.Text = ""         .FirstPage.CenterFooter.Text = ""         .FirstPage.RightFooter.Text = ""     End With          Application.PrintCommunication = True End Sub  ' 工作表000的特定设置 Private Sub ApplySheet000Settings(ws As Worksheet)     With ws.PageSetup         .Orientation = xlPortrait         .FitToPagesWide = 1         .FitToPagesTall = 0     End With End Sub  ' 工作表003的特定设置 Private Sub ApplySheet003Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         ' 设置为横向         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False                  ' 打印区域         .PrintArea = "$A$1:$BF$80"         .PrintTitleRows = "$1:$8"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.669)         .BottomMargin = Application.InchesToPoints(0.591)     End With          Application.PrintCommunication = True          ' 设置列宽和行高     With ws         ' 设置列宽         .Columns("C:BF").ColumnWidth = 1.88         .Columns("E:E").ColumnWidth = 7.5         .Columns("F:F").ColumnWidth = 7.5         .Columns("AS:AS").ColumnWidth = 7.5         .Columns("AT:AT").ColumnWidth = 7.5         .Columns("BF:BF").ColumnWidth = 11.29                  ' 设置行高         .Rows("1:1").RowHeight = 10.5         .Rows("2:2").RowHeight = 27         .Rows("3:3").RowHeight = 44.25         .Rows("7:7").RowHeight = 81         .Rows("8:80").RowHeight = 18                  ' 设置字体         .Range("C10:BF80").Font.Name = "宋体"         .Range("C10:BF80").Font.Size = 9         .Range("A4:BF80").Font.Size = 10                  ' 替换文本         .Range("AT3").Replace What:="金额单位:?$", Replacement:="金额单位:万元", LookAt:=xlPart         .Range("BF3").Value = "表号:003" & Chr(10) & "金额单位:万元"     End With End Sub  ' 工作表002的特定设置 Private Sub ApplySheet002Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False         .PrintTitleRows = "$1:$4"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.709)         .BottomMargin = Application.InchesToPoints(0.63)     End With          Application.PrintCommunication = True          With ws         ' 设置行高         .Rows("1:1").RowHeight = 17.25         .Rows("2:2").RowHeight = 20.25         .Rows("3:3").RowHeight = 26.25         .Rows("4:75").RowHeight = 14                  ' 设置列宽         .Columns("F:F").ColumnWidth = 47.57                  ' 设置字体         .Range("F31,F69,F70").Font.Name = "宋体"         .Range("F31,F69,F70").Font.Size = 6     End With End Sub  ' 工作表001的特定设置 Private Sub ApplySheet001Settings(ws As Worksheet)     Application.PrintCommunication = False          With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False         .PrintTitleRows = "$1:$8"                  ' 自定义边距         .LeftMargin = Application.InchesToPoints(0.748)         .RightMargin = Application.InchesToPoints(0.748)         .TopMargin = Application.InchesToPoints(0.984)         .BottomMargin = Application.InchesToPoints(0.827)     End With          Application.PrintCommunication = True          With ws         ' 设置列宽         .Columns("C:AF").ColumnWidth = 9     End With End Sub  ' 通用工作表设置 Private Sub ApplyGeneralSheetSettings(ws As Worksheet)     ' 默认设置为横向     With ws.PageSetup         .Orientation = xlLandscape         .FitToPagesWide = 1         .FitToPagesTall = False     End With          ' 替换所有工作表中的"金额单位:?$"     On Error Resume Next     ws.Cells.Replace What:="金额单位:?$", Replacement:="金额单位:万元", LookAt:=xlPart     On Error GoTo 0 End Sub  ' 快捷打印宏 Sub QuickPrintAll()     ' 直接打印所有配置好的工作表     On Error GoTo PrintError          Application.ScreenUpdating = False          Dim sheetNames As Variant     sheetNames = Array("000", "003", "002", "100", "101", "102", "104", "105", _                        "106", "107", "108", "109", "900", "103", "001")          Dim wsNames() As String     ReDim wsNames(0 To UBound(sheetNames))          Dim i As Long     For i = 0 To UBound(sheetNames)         wsNames(i) = CStr(sheetNames(i))     Next i          ' 选择并打印所有工作表     ThisWorkbook.Sheets(wsNames).Select     ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True      CleanUp:     Application.ScreenUpdating = True     Exit Sub      PrintError:     MsgBox "打印错误: " & Err.Description, vbExclamation     Resume CleanUp End Sub  ' 恢复默认设置(可选) Sub ResetPrintSettings()     Dim ws As Worksheet     Dim response As VbMsgBoxResult          response = MsgBox("确定要重置所有工作表的打印设置吗?", vbYesNo + vbQuestion, "确认重置")          If response = vbYes Then         Application.ScreenUpdating = False                  For Each ws In ThisWorkbook.Worksheets             With ws.PageSetup                 ' 恢复默认设置                 .LeftHeader = ""                 .CenterHeader = ""                 .RightHeader = ""                 .LeftFooter = ""                 .CenterFooter = ""                 .RightFooter = ""                 .LeftMargin = Application.InchesToPoints(0.75)                 .RightMargin = Application.InchesToPoints(0.75)                 .TopMargin = Application.InchesToPoints(1)                 .BottomMargin = Application.InchesToPoints(1)                 .HeaderMargin = Application.InchesToPoints(0.5)                 .FooterMargin = Application.InchesToPoints(0.5)                 .PrintHeadings = False                 .PrintGridlines = False                 .CenterHorizontally = False                 .CenterVertically = False                 .Orientation = xlPortrait                 .PaperSize = xlPaperA4                 .FirstPageNumber = xlAutomatic                 .Zoom = 100                 .PrintArea = ""                 .PrintTitleRows = ""                 .PrintTitleColumns = ""             End With         Next ws                  Application.ScreenUpdating = True         MsgBox "打印设置已重置为默认值!", vbInformation     End If End Sub
回复

使用道具 举报

30#
发表于 昨天 08:39 来自手机 | 只看该作者
试试上面宏代码

点评

没法运行[attachimg]571691[/attachimg] [attachimg]571691[/attachimg]  详情 回复 发表于 昨天 08:55
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2026-2-6 04:00

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表