在外贸业务中,经常要跨平台调用文件,从ERP系统或在线下单平台导出的订单,通常不能直接发送给客户,如何快速转化为自己想的格式呢?用VBA进行一键转化是不错的选择。
以下为操作流程:
- 确定要保留哪些内容。此处我选择了产品编号、属性、图片、单价、数量、小计
- 编写宏。可以在【开发工具】选项卡下创建/录制宏
- 为宏指定快捷键。【开发工具】选项卡 - 宏 - 选项
导出时的样式
转化后的样式
完整宏代码及解释
Sub 宏1()
'统一格式: 字号,行高,垂直居中对齐
Cells.Font.Size = 12
Cells.RowHeight = 40
Cells.VerticalAlignment = xlVAlignCenter
'统一图片尺寸与位置
ActiveSheet.DrawingObjects.ShapeRange.Height = 28.3464566929
ActiveSheet.DrawingObjects.ShapeRange.IncrementTop -18
ActiveSheet.DrawingObjects.ShapeRange.IncrementLeft 8
'删除多余的行与列
Cells.UnMerge
Rows("1:2").Delete
Range("A:A,C:D,G:H").Delete
Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'调整列位置 - 整理颜色 - 整理价格
Columns("A:A").Cut
Columns("D:D").Insert Shift:=xlShiftToRight
Columns("B:B").Replace What:="{""color"":""", Replacement:=""
Columns("B:B").Replace What:="""}", Replacement:=""
Range("D:D, F:F").NumberFormatLocal = "#,##0.00_ ;[红色]-#,##0.00"
Columns("E:E").NumberFormatLocal = "#,##0 ;[红色]-#,##0.00"
Columns("F:F").HorizontalAlignment = xlHAlignRight
'按产品型号排序
Columns("A:F").Sort [A1]
End Sub
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33