-
21-12-2019 - |
题
我有下面打开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
. 解决方案
“...打开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
. 其他提示
这将保存一个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
. 不隶属于 StackOverflow