问题
With the below entered script I want my workbook to be saved with the name entered by the user, say
Sub save_workbook_name()
Dim workbook_Name As Variant
Dim location As String
workbook_Name = Application.GetSaveAsFilename(fileFilter:="Excel binary sheet (*.xlsb), *.xlsb", InitialFileName:="N:\IRi\Periode Rapportage Px")
If workbook_Name <> False Then
ActiveWorkbook.SaveAs WriteResPassword:="TM", FileFormat:=50
End If
End Sub
But when I now try to save the file with a different name, lets say with the X replaced by 9, it turns out the script only allows to save with the same file name as the original filename. So I entered Periode Rapportage P9(.xlsb) and then Excel saves the file with filename Periode Rapportage Zelfzorg v2.xlsb.
Any clues on why this happens? The original file is saved with a password to write security.
Entered desired filename:
popup question after pressing ok/save:
Apparently the entered desired filename was changed back to its original filename.
Is there any way to solve this and make the script save the file with the name entered by the user?
回答1:
You didn't include a file name in the saveas line:
ActiveWorkbook.SaveAs filename:=workbook_name, WriteResPassword:="TM", FileFormat:=50
来源:https://stackoverflow.com/questions/52258113/vba-script-to-save-workbook-overwrites-entered-filename