我用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文件成功!"
运行结果是弹出一个保存界面,读取文档的第一行字为文件名,然后按保存才能保存成功。问题1:但是由Appword.ActiveDocument.SaveAs FileName:=(txtName.Text & ".doc"), 代码控制保存的文档内却没有内容。问题2:如果已经开启了一个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文件成功!"
运行结果是弹出一个保存界面,读取文档的第一行字为文件名,然后按保存才能保存成功。问题1:但是由Appword.ActiveDocument.SaveAs FileName:=(txtName.Text & ".doc"), 代码控制保存的文档内却没有内容。问题2:如果已经开启了一个word文档的话,会弹出无法保存的错误。
亟待解决,谢谢高手指教!
解决方案 »
- 打包后安装无法继续
- 问一个简单问题,大家请指点!
- 如何将一个目录下的所有DBF文件导入SQL中的一个表中?
- <沁园春·血>作者:萨达姆
- 关于文本和图片在数据库中共存的问题(急急急急急急急急!!!!!)
- 如何将程序安装时自动添加到启动菜单里?
- 怎么样把.RTF文件转化为HLP文件,这样的帮助系统,请指教.
- 问你个问题,MEDIAPLAYER播放VCD是默认为左声道,解霸默认为立体声,如果在编程中使MEDIAPLAYER播放为立体声
- Crystal Report 中能不能实现这种形式的打印??
- 求助!我是初学者,需要大家指教。
- excel2003已经成功安装一个插件,但是找不到
- Tiger_Zhao 能否把你的syn文件给我一份
然后,再将文件移动到指定的文件夹中即可!
Appword.ActiveDocument.SaveAs FileName:="c:\111.doc"
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文件成功!"
正解,昨天晚上我测试后已经行了。非常感谢。