首页 > 解决方案 > 复制 word 模板文件并根据导出的列表将其保存为各种文件名

问题描述

对于工作,我们的客户要求我们生成一个包含网格内各个位置的 GIS 图像、地址和支持地图信息的 Word 文档。我们还被要求提取每个引用位置的规格表。由于网格上可以显示多个位置,因此可以创建文档与图像的不对称比例

通常,当前过程包括复制工作 Word 文档、更改所需信息、保存然后做同样的事情,直到我们完成。

为了尝试简化此过程,我当前的方法涉及运行批处理命令以列出文件夹目录中的图像文件

DIR /s *.JPG > ImageList.xls

然后使用 excel 运行宏以删除标题、预告片和不需要的元数据

Sub ImageList()
Set WS_Input = Worksheets("ImageList")

For i = 5 To 1 Step -1
Rows(i).EntireRow.Delete
Next
'Removes Header Information
'CODE WORKS


Last = Cells(Rows.Count, "A").End(xlUp).Row
Last5 = Last - 5
For i = Last To Last5 Step -1
Rows(i).EntireRow.Delete
Next
'Removes trailer information
'CODE WORKS

Last = Cells(Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
A_length = Len(Range("A" & i))
'Determining the total string length including the leading 39 unneeded characters
A_length39 = A_length - 39
'Determining the total string length removing the leading 39 unneeded characters
Range("A" & i).Copy
WS_Input.Range("A" & i).Value = Right(WS_Input.Range("A" & i), A_length39)
'Removes the unneeded leading characters and repastes them
 Next

End Sub

这就是我卡住的地方;我最好运行批处理命令(为此我不确定如何通过为每次迭代提供不同的名称来循环命令提示符,因为大多数示例似乎都将后缀或前缀附加到已经存在的文件)或编写word 中的附加宏(同样,我不确定如何让 vba word 引用清理后的 excel 列表)。

我是团队中唯一真正尝试实施此类方法的人,因此尽管我得到了老板的支持,但他们不知道如何提供帮助。

标签: excelvbabatch-filems-word

解决方案


推荐阅读