Sub FileSaveAs()
Const fPath = "C:\Users\yongle\OneDrive\Documents\Excel"
Dim fileSaveName As Variant, fileExt As String, filterStr As String, fFormat
[COLOR=#000080]'build string of accceptable formats[/COLOR]
filterStr = "Excel Macro-Enabled Workbook (*.xlsm),*.xlsm," + "PDF (*.pdf),*.pdf," + "CSV (Comma delimited)(*.csv),*.csv,"
'[COLOR=#000080]user provides the name (exit sub if user cancels)[/COLOR]
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=fPath, fileFilter:=filterStr)
If fileSaveName = False Then
MsgBox "name missing"
Exit Sub
End If
[COLOR=#000080]'create file based on user selection[/COLOR]
fileExt = Right(fileSaveName, Len(fileSaveName) - InStrRev(fileSaveName, "."))
If fileExt = "pdf" Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileSaveName
Else
Select Case fileExt
Case "csv": fFormat = xlCSV
Case Else: fFormat = xlOpenXMLWorkbookMacroEnabled
End Select
ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=fFormat
End If
End Sub