VBA代码文档filedialog.saveas

时间:2016-07-14 09:12:10

标签: access-vba word-vba savefiledialog

我是Access 2010-VBA中编写代码的新手,非常感谢您的帮助。我使用了MO 14.0对象库 我想要: - 点击按钮 打开filedialog.saveas,用户可以在其中选择保存word文档的方向。然后打开文档并从访问数据库中写入内容。 在我的路上,我发现了如何打开,填写数据以及如何打开文件管理...问题是所选的数据文件没有保存在它应该的位置。 缺少什么,错误在哪里?

`

Private Sub Befehl44_Click()
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
  With objWord
    .Visible = True
    .Documents.Open (CurrentProject.Path & "\template.docx") 'template for word document
    .activedocument.Bookmarks("email").Select 
    .Selection.Text = Me!email 
    .activedocument.Bookmarks("name").Select
    .Selection.Text = Me!name
    .Application.FileDialog(msoFileDialogSaveAs).Show
    strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)
  End With
Set objWord = Nothing
End Sub

`

1 个答案:

答案 0 :(得分:0)

strPath是否返回用户选择保存的正确文件路径?

如果是,您只需要直接从Word调用SaveAs方法

之后

strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)

插入行
If strPath <> "" Then .ActiveWorkbook.SaveAs strPath End If

或 - 只需将其替换为一行

ActiveWorkbook.SaveAs filename:=Application.GetSaveAsFilename