Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1") If tr.Nodes.Count = 0 Then MessageBox.Show("没有添加文档!", "提示") Else Dim app As New MSWord.Application Dim nn As WinForm.TreeNode Dim ere As Integer = tr.Nodes.Count - 1 Dim bb As Integer For bb = 0 To ere nn = tr.Nodes(bb) app.Documents.open(nn.Text) app.Documents(nn.Text).Activate app.ActiveDocument.Content.Select app.Selection.Copy app.Documents(nn.Text).close 'app.Documents.Open(ProjectPath & "合并.docx") '设定保存文件名称可以,下面的指定路径和文件名称保存不行 Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog dlg.Filter= "word|*.doc" '设置筛选器 dlg.FileName = "合并.doc" If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 MessageBox.Show("你要保存为:" & dlg.FileName,"提示") '提示用户选择的文件 app.Documents.Open(dlg.FileName) app.Visible = True app.Selection.Paste() Else app.Visible = True End If Next End If
|