【问题标题】:Saving Access Report保存访问报告
【发布时间】:2014-01-10 02:15:02
【问题描述】:

我有以下打开另存为对话框,但是当我单击保存时它实际上并没有保存文件。

Dim SaveBox As Object
Set SaveBox = Application.FileDialog(msoFileDialogSaveAs)

With SaveBox
.AllowMultiSelect = False
.InitialFileName = "WeeklyLog " & Format(Now, "yyyy_mm_dd")
SaveBox.Show
End With

【问题讨论】:

  • 您要保存为文本文件吗? Excel电子表格? Word 文档?
  • 作为 pdf。在刷新页面并查看您的问题之前,我在下面问过它。

标签: ms-access ms-access-2007 vba


【解决方案1】:

"...打开另存为对话框,但是当我单击保存时它实际上并没有保存文件"

FileDialog 可以给你一个包含文件路径的字符串。但它实际上并没有执行“另存为”操作。开发人员可以在代码中使用该文件路径将某些内容保存在某处,这取决于您。

Dim SaveBox As Object
Dim strFilePath As String

Set SaveBox = Application.FileDialog(2) ' msoFileDialogSaveAs
With SaveBox
    .InitialFileName = "WeeklyLog " & Format(Date, "yyyy_mm_dd")
    If .Show = True Then
        strFilePath = .SelectedItems(1)
    End If
End With

' now do something with strFilePath ...
If Len(strFilePath) > 0 Then
    MsgBox "File path: " & strFilePath
Else
    MsgBox "Selection cancelled."
End If

【讨论】:

  • 知道了,很高兴知道。我添加了 DoCmd.OutputTo acOutputReport, "WeeklyLogReport", acFormatPDF, strFilePath, False,它只是保存文件而不是 pdf。只是一个没有扩展名的文件。
  • der...只需在 .InitialFileName = "WeeklyLog" & Format(Date, "yyyy_mm_dd") & ".pdf" 中添加“.pdf”。感谢您的帮助。
【解决方案2】:

这将保存一个 Excel 文件,我认为您只需稍作调整即可保存 PDF:

Sub GetFileName()
    Dim fd As FileDialog
    Dim fname As String

    Do
        Set fd = Application.FileDialog(msoFileDialogSaveAs)
        With fd
            .AllowMultiSelect = False
            .InitialFileName = "New To Do.xls"
            If .Show = -1 Then fname = .SelectedItems(1)

            If fname = fd.InitialFileName Then _
                MsgBox "Please enter a new filename", vbOKOnly, "Filename Needed!"
        End With
    Loop Until fname <> fd.InitialFileName

    If IsEmpty(fname) Or fname = vbNullString Then Exit Sub
    ThisWorkbook.SaveAs fname

End Sub

【讨论】:

  • 实际上只需要 .InitialFileName = "WeeklyLog" & Format(Date, "yyyy_mm_dd") & ".pdf" 谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多