我用VB在指定文件夹里读取一个word模版,里面是一个表,把数据库的内容写入word中,写可以成功了。
现在问题是保存,我想设定直接保存在指定的文件夹中。
先贴出我现在完成的代码:
Dim Appword As Word.Application
Dim Newword As Word.Document
Set Appword = New Word.Application
Set Newword = Appword.Documents.Add(App.Path + "\stencil" + "\stencil.doc")
Appword.Visible = True
Appword.WindowState = wdWindowStateMinimize
Appword.Documents.Add
With Newword
.Tables(1).Cell(1, 1).Range.Text = txtName.Text
End With
Appword.ChangeFileOpenDirectory (App.Path + "\Result")
Appword.ActiveDocument.SaveAs FileName:=(txtName.Text & ".doc"), FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
Appword.Documents.Close
Appword.Quit
MsgBox "导出Word文件成功!"