[英]VBA SaveAs saving as File type instead of .xlsm
When a user opens up this workbook, I want to force them to save the file as a new file immediately. 当用户打开此工作簿时,我要强制他们立即将文件另存为新文件。 The dialog box opens up but it will only let you save it as "All Files".
对话框打开,但只允许您将其另存为“所有文件”。
Dim Workbook_Orig As Variant
Workbook_Orig = Application.GetSaveAsFilename
If Workbook_Orig <> False Then
ActiveWorkbook.SaveAs _
Filename:="File Name", _
FileFormat:=52
End If
In place of the "52" I've tried "xlOpenXMLWorkbookMacroEnabled" but that made no difference. 我尝试使用“ xlOpenXMLWorkbookMacroEnabled”代替“ 52”,但这没有什么区别。
Can you not SaveAs immediately? 您不能立即另存为吗? Do you have to make a change to the file or something?
您是否需要更改文件或其他内容?
Any help is greatly appreciated. 任何帮助是极大的赞赏。
Try specifying a file filter : 尝试指定文件过滤器 :
Workbook_Orig = Application.GetSaveAsFilename( _
fileFilter:="XLSM Files (*.xlsm), *.xlsm")
Changing the FileFormat
only matters if they don't select anything in the dialogue box (since that is the only time workbook_orig = False) 仅当他们在对话框中没有选择任何内容时,更改
FileFormat
才是重要的(因为这是workbook_orig = False的唯一时间)
Try specifying the file filter parameter 尝试指定文件过滤器参数
Workbook_Orig = Application.GetSaveAsFilename(fileFilter:="Excel Macro-Enabled Workbook (*.xlsm),*.xlsm")
In your GetSaveAsFileName
instruction. 在您的
GetSaveAsFileName
指令中。
Why not present the user with an InputBox? 为什么不向用户显示InputBox? Have them enter the new file name and have the macro perform the save as.
让他们输入新的文件名,并让宏执行另存为。
Something like: 就像是:
Sub saveAs()
userAnswer = InputBox("Please enter filename")
ActiveWorkbook.saveAs Filename:= _
"C:\" & userAnswer & ".xls", FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub
EDIT 编辑
Sub saveAs()
userAnswer = InputBox("Please enter filename")
userDirectory = InputBox("Please enter directory to save file")
ActiveWorkbook.saveAs Filename:= _
userDirectory & "\" & userAnswer & ".xls", FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.