保存访问报告

时间:2014-01-09 17:19:31

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

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

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

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

2 个答案:

答案 0 :(得分:2)

“...打开SaveAs对话框,但是当我点击”

时,它实际上并没有保存文件

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

答案 1 :(得分:0)

这将保存一个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