Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "word|*.doc" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
MessageBox.Show("你要保存为:" & dlg.FileName,"提示") '提示用户选择的文件
Dim app1 As New MSWord.Application
Dim app2 As new msword.application
try
For i As Integer =1 To Vars("_xz7")
Dim doc1 = app1.Documents.Open(ProjectPath & "相关性图\xgx" & i & ".doc")
app1.ActiveWindow.Selection.WholeStory
app1.ActiveWindow.Selection.Copy
Doc1.Close
Dim doc2 As Object
If i=1 Then
doc2 = app2.Documents.Open(dlg.filename) ‘这句代码本意是想打开新建的word文件,可是并没有新建的word文件,
如何才能新建一个word文件,并能指定名称保存,然后再打开这个新建的文件呢?这样将所有合并的文件内容都加入到这个文件中去。
app2.ActiveWindow.Selection.WholeStory
app2.ActiveWindow.Selection.delete
End If
app2.ActiveWindow.Selection.WholeStory
app2.ActiveWindow.Selection.MoveRight(Unit:=1, Count:=1)
app2.ActiveWindow.Selection.TypeParagraph
app2.ActiveWindow.Selection.Paste
Next
app2.Documents.save()
'app.visible = True
catch ex As exception
msgbox(ex.message)
finally
app2.quit
app1.quit
messagebox.show("已生成Word文件!")
End try
End If