|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 1we123 于 2024-11-10 15:13 编辑
function test(){
const doc = ActiveDocument;
const path = doc.Path + '\\邮件合并数据源.xls';
doc.MailMerge.OpenDataSource(path);
doc.MailMerge.Execute(0);
}
改成这样也是可以运行的,对比vba的代码,好像差了用数据源的那个表格作数据这一段,还有差另存为其他文件名了
File1 = ThisWorkbook.Path & "\模板\" & Sheet1.Cells(i, 26) & "封面.doc"
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open(File1)
Set MMerge = WordDoc.MailMerge
With MMerge
.OpenDataSource Name:=SEFile, SQLStatement:="SELECT * FROM `Sheet3$`" \\差这一句怎么改为JSA了,楼主加油
.Execute: WordDoc.Close
With WordApp
.Visible = True: .Application.WindowState = xlNormal:
.ActiveDocument.SaveAs Filename:= _
ThisWorkbook.Path & "\" & arr(2, 1) & "第" & arr(2, 2) & "学期" & "\" & arr(i, 16) & "\" & arr(i, 16) & arr(i, 9) & ")" & "封面.doc"
WordApp.Quit
End With
End With
|
|