ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 12369|回复: 25

[求助] Excel表根据指定数据自动填入固定模板,自动选地方另存、预览和批量打印

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-7-18 14:27 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
各位大神老师好。

       由于工作需要,复制粘贴量比较庞大,需要将“列表”中的数据填入“模板”中,能否请各位大神老师帮忙设一下代码:
1、根据“列表”中的B列的同类人名数据(收付号可能会不同,存在一条或多条收付号,收付号顺序未必连号),自动填入“模板”中对应的格式中。
2、由于可能收付号会多于两条,“模板”中能否自动增加行填列。
3、“模板”中实发金额=手续费-税费,“模板”中的合计能自动计算。
4、由于列表人数会比较多,能否自动以“模板”中的收款人全称+实发金额命名,提示选择路径另存表格,并提示预览和批量打印。

在此,先谢谢各位老师,希望能得到大神们的帮助,个人会努力学习的,谢谢。

个人代支表另存2.rar

16.4 KB, 下载次数: 122

TA的精华主题

TA的得分主题

发表于 2019-7-18 15:53 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
如果你的目的只是想打印的话,并不需要点击另存那么多文件,可以直接批量打印的。

TA的精华主题

TA的得分主题

发表于 2019-7-18 15:55 | 显示全部楼层
如果你的目的只是想打印的话,并不需要点击另存那么多文件,可以直接批量打印的。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-18 15:57 | 显示全部楼层
tao60 发表于 2019-7-18 15:53
如果你的目的只是想打印的话,并不需要点击另存那么多文件,可以直接批量打印的。

除了要打印,还是得另存,因为不同的渠道收款人可能有几个,然后不同的渠道会查数,所以还是要另存,所以很麻烦。。。。。。每天都在加班。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-18 15:58 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
tao60 发表于 2019-7-18 15:55
如果你的目的只是想打印的话,并不需要点击另存那么多文件,可以直接批量打印的。

打印是为了给财务支付,另存是为了给渠道查数

TA的精华主题

TA的得分主题

发表于 2019-7-18 18:27 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 tao60 于 2019-7-22 09:09 编辑

好久没写VBA了,很多代码都不记得了,很多代码都是通过录制宏生成的,然后再进行精简和修改。
功能基本实现了,细节功能,可以自己研究一下。
  1. 'tao60  2019-07-18

  2. Sub AllData()
  3. '开始批处理

  4.     Dim iRow As Integer
  5.     Dim iRowBegin As Integer
  6.     Dim iRowEnd As Integer
  7.     Dim iRow_all As Integer
  8.     Dim strUser As String
  9.     Dim stemp As String
  10.     Dim strPath As String
  11.    
  12.    
  13.     Dim shtList As Object
  14.     Dim shtOut As Object
  15.     Set shtList = Sheets("列表")
  16.     Set shtOut = Sheets("模板")
  17.    
  18.     '选择保存路径
  19.     With Application.FileDialog(msoFileDialogFolderPicker)
  20.         .Title = "选择要保存的路径……"
  21.         If .Show = False Then
  22.            Exit Sub
  23.         End If
  24.         
  25.         strPath = .SelectedItems(1)
  26.     End With
  27.    
  28.     '列表最大行号
  29.     iRow_all = shtList.Range("A65535").End(xlUp).Row
  30.    
  31.     iRowBegin = 2
  32.     strUser = Trim(shtList.Cells(2, 4))
  33.    
  34.     '从列表开始行号2开始处理
  35.     For iRow = 2 To iRow_all Step 1
  36.         stemp = Trim(shtList.Cells(iRow, 4))
  37.         
  38.         If strUser <> stemp Or iRow = iRow_all Then
  39.             iRowEnd = iRow - 1
  40.             '处理最后一行2019-07-22
  41.             If iRow = iRow_all Then
  42.                 iRowEnd = iRow_all
  43.             End If
  44.             '处理同一个收款人的数据,保存到一个文件,请先对列表数据进行排序,按照收款人进行排序
  45.             Call PathData(iRowBegin, iRowEnd, strUser, strPath)
  46.             
  47.             iRowBegin = iRow
  48.             strUser = shtList.Cells(iRow, 4)
  49.         End If
  50.     Next

  51. End Sub

  52. Function PathData(iBegin As Integer, iEnd As Integer, sName As String, sPath As String)
  53. '子程序 根据列表起止行号将列表数据写入到模板中,并另外文件和打印
  54. 'iBegin 开始行号, iEnd 结束行号, sName 文件名, sPath 另存文件路径

  55.     If iBegin = 0 Or iEnd = 0 Or iBegin > iEnd Then
  56.       Exit Function
  57.     End If
  58.    
  59.     Dim shtList As Object
  60.     Dim shtOut As Object
  61.     Set shtList = Sheets("列表")
  62.     Set shtOut = Sheets("模板")
  63.    
  64.     shtOut.Rows("4:65535").Delete Shift:=xlUp '删除所有数据行
  65.    
  66.     Dim iRowList As Integer
  67.     Dim iRowOut As Integer
  68.     Dim iCount As Integer
  69.    
  70.     iCount = 1
  71.     iRowOut = 4 '模板用于填写数据的位置行号
  72.     For iRowList = iBegin To iEnd Step 1
  73.         shtOut.Range("A" & iRowOut).Value = iCount
  74.         shtOut.Range("B" & iRowOut).Value = "'" & shtList.Range("B" & iRowList).Value
  75.         shtOut.Range("C" & iRowOut).Value = "'" & shtList.Range("C" & iRowList).Value
  76.         shtOut.Range("D" & iRowOut).Value = shtList.Range("H" & iRowList).Value
  77.         shtOut.Range("E" & iRowOut).Value = shtList.Range("I" & iRowList).Value
  78.         shtOut.Range("F" & iRowOut).Value = shtList.Range("J" & iRowList).Value
  79.         shtOut.Range("G" & iRowOut).FormulaR1C1 = "=RC[-3]-RC[-2]"
  80.         shtOut.Range("H" & iRowOut).Value = "'" & shtList.Range("D" & iRowList).Value
  81.         shtOut.Range("I" & iRowOut).Value = "'" & shtList.Range("E" & iRowList).Value
  82.         shtOut.Range("J" & iRowOut).Value = "'" & shtList.Range("F" & iRowList).Value
  83.         iCount = iCount + 1
  84.         iRowOut = iRowOut + 1
  85.     Next
  86.    
  87.     '汇总行
  88.     shtOut.Range("A" & iRowOut).Value = "合计"
  89.     shtOut.Range("A" & iRowOut & ":J" & iRowOut).Font.Bold = True
  90.     shtOut.Range("D" & iRowOut).FormulaR1C1 = "=SUM(R[-" & iCount - 1 & "]C:R[-1]C)"
  91.     shtOut.Range("E" & iRowOut).FormulaR1C1 = "=SUM(R[-" & iCount - 1 & "]C:R[-1]C)"
  92.     shtOut.Range("F" & iRowOut).FormulaR1C1 = "=SUM(R[-" & iCount - 1 & "]C:R[-1]C)"
  93.     shtOut.Range("G" & iRowOut).FormulaR1C1 = "=SUM(R[-" & iCount - 1 & "]C:R[-1]C)"

  94.     '边框线
  95.     shtOut.Range("A4:J" & iRowOut).Borders(xlEdgeLeft).LineStyle = xlContinuous
  96.     shtOut.Range("A4:J" & iRowOut).Borders(xlEdgeTop).LineStyle = xlContinuous
  97.     shtOut.Range("A4:J" & iRowOut).Borders(xlEdgeBottom).LineStyle = xlContinuous
  98.     shtOut.Range("A4:J" & iRowOut).Borders(xlEdgeRight).LineStyle = xlContinuous
  99.     shtOut.Range("A4:J" & iRowOut).Borders(xlInsideVertical).LineStyle = xlContinuous
  100.     shtOut.Range("A4:J" & iRowOut).Borders(xlInsideHorizontal).LineStyle = xlContinuous
  101.    
  102.     '字体
  103.     shtOut.Range("A4:J" & iRowOut).Font.Name = "宋体"
  104.     shtOut.Range("A4:J" & iRowOut).Font.Size = 10
  105.     shtOut.Range("A4:A" & iRowOut).HorizontalAlignment = xlCenter
  106.    
  107.     '底部签名栏
  108.     shtOut.Range("A" & iRowOut + 3).Value = "分公司负责人:                财务负责人:               业管部负责人:              渠道部负责人:                财务复核:"
  109.     shtOut.Range("A" & iRowOut + 6).Value = "代理人:                  制表:"
  110.     shtOut.Range("A" & iRowOut + 9).Value = "总公司分管会计:"
  111.    
  112.     '另存文件
  113.     Dim sFileName As String
  114.     Dim wbOut As Object
  115.    
  116.     sFileName = sPath & "" & sName & ".xlsx"
  117.     shtOut.Copy
  118.     Set wbOut = ActiveWorkbook
  119.     wbOut.ActiveSheet.Name = sName
  120.     wbOut.SaveAs Filename:=sFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, ConflictResolution:=xlLocalSessionChanges
  121.    
  122.     '直接打印 无预览
  123.     wbOut.ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
  124.    
  125.     '关闭
  126.     wbOut.Close False
  127. End Function

  128. Function test()
  129.     'DEMO测试
  130.     Call PathData(2, 5, "四四", "D:\2345Downloads")
  131.    
  132. End Function
复制代码


个人代支表另存Test.zip

27.73 KB, 下载次数: 370

评分

2

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-7-18 18:29 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2019-7-18 18:31 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2019-7-18 19:34 来自手机 | 显示全部楼层
yoyolee22 发表于 2019-7-18 15:57
除了要打印,还是得另存,因为不同的渠道收款人可能有几个,然后不同的渠道会查数,所以还是要另存,所以 ...

每天都是加班,不会吧。。。工资高吗?

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-7-18 19:56 来自手机 | 显示全部楼层
公司系统落后到爆,提了三年需求,IT还说要排期,前段时间还在问有什么需求。本来系统可以直接输出的数据,还得导几个表再比出来,完了还得做这种费时的事,您觉得这样连系统都不愿投入建设的公司工资会高么。苦逼啊。。。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-17 12:25 , Processed in 0.038685 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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