Public Sub Example()
Dim oWb As Workbook
Dim sMyFile As String
Dim sSavedFile As String
sMyFile = "C:\Users\ItalianPlatinum\Documents\MyData.CSV" ' <<< change as required
Set oWb = ActiveWorkbook ' <<< change as required
' return with drive:\folder\filename.ext of saved file
sSavedFile = FileSaveAs(oWb, sMyFile)
Set oWb = Nothing
End Sub
Public Function FileSaveAs(argWbk As Workbook, argFileFullName As String) As String
Dim sFileName As String
Dim sFileExt As String
Dim sFilters As String
Dim iFiltIx As Integer
Dim vFormat As Long
' compose string of used formats
sFilters = "Excel Workbook (*.xlsx),*.xlsx," + _
"Excel Macro-Enabled Workbook (*.xlsm),*.xlsm," + _
"CSV (Comma delimited)(*.csv),*.csv,"
' get initial file extension
sFileExt = Right(argFileFullName, Len(argFileFullName) - InStrRev(argFileFullName, "."))
' set current filter accordingly
Select Case LCase(sFileExt)
Case "xlsx": iFiltIx = 1
Case "xlsm": iFiltIx = 2
Case "csv": iFiltIx = 3
Case Else: iFiltIx = 1
End Select
' user provides final folder and file name
sFileName = Application.GetSaveAsFilename(InitialFileName:=argFileFullName, _
FileFilter:=sFilters, _
FilterIndex:=iFiltIx)
If sFileName = "False" Then
MsgBox "User has canceled.", vbExclamation, "SaveAs"
FileSaveAs = ""
GoTo SUB_DONE
End If
' get final file extension
sFileExt = Right(sFileName, Len(sFileName) - InStrRev(sFileName, "."))
' save file as requested
Select Case LCase(sFileExt)
Case "xlsx": vFormat = xlOpenXMLWorkbook
Case "xlsm": vFormat = xlOpenXMLWorkbookMacroEnabled
Case "csv": vFormat = xlCSV
Case Else: vFormat = xlOpenXMLWorkbook
End Select
argWbk.SaveAs Filename:=sFileName, FileFormat:=vFormat
FileSaveAs = sFileName
SUB_DONE:
End Function