如何使用 Excel 宏生成或创建一系列 Word 文件?
如何创建文件名作为 B(2-9999) 中单元格的 Word 文件序列?
我能够生成文件,但它被保存为 1,2,3,4...
例如
A B
Title Titletopic
11111 Fantasy Golf Resort
222 Golden Palms Resort & Spa
3333 Guest Line Hotels & Resorts
4444 Parkfield Resotel
555 Shreyas Retreat
666 Patels Inn
777 Plantation Trails
888 giri
9999 neil
我的代码是
Sub ControlWord()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application.12")
appWD.Visible = True
Sheets("Sheet1").Select
FinalRow = Range("A9999").End(xlUp).Row
For i = 2 To FinalRow
Sheets("Sheet1").Select
Range("A" & i & ":B" & i).Copy
appWD.Documents.Add
appWD.Selection.Paste
appWD.ActiveDocument.SaveAs Filename:="" & i
Next i
End Sub
How can i create a sequence of word files with file name as cells in B(2-9999) ?
I am able to generate files but it gets saved as 1,2,3,4....
Eg
A B
Title Titletopic
11111 Fantasy Golf Resort
222 Golden Palms Resort & Spa
3333 Guest Line Hotels & Resorts
4444 Parkfield Resotel
555 Shreyas Retreat
666 Patels Inn
777 Plantation Trails
888 giri
9999 neil
my code is
Sub ControlWord()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application.12")
appWD.Visible = True
Sheets("Sheet1").Select
FinalRow = Range("A9999").End(xlUp).Row
For i = 2 To FinalRow
Sheets("Sheet1").Select
Range("A" & i & ":B" & i).Copy
appWD.Documents.Add
appWD.Selection.Paste
appWD.ActiveDocument.SaveAs Filename:="" & i
Next i
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用计数器变量而不是单元格值,因此您假设想要
"11111 Fantasy Golf Resort.docx"
或者假设第一个感兴趣的单元格是“A2”;
Your using the counter variable not the cell value, so you assuming want
"11111 Fantasy Golf Resort.docx"
Or alternatively assuming the 1st cell of interest is "A2";