jmac001
asked on
Saving a File Under a New Name
Hi, I'm writing a macro that will save a file under a new name. I will need it to give the user an option to choose the name and the location to save the file.
I have the following code: A Syntax Error message appears and I'm not sure how to fix this.
I have the following code: A Syntax Error message appears and I'm not sure how to fix this.
Sub Save_File()
'
' Save_File Macro
Dim ActSheet As Worksheet
Dim ActBook As Workbook
Dim CurrentFile As String
Dim NewFileType As String
Dim NewFile As String
Application.ScreenUpdating = False ' Prevents screen refreshing.
CurrentFile = ThisWorkbook.FullName
[b]
NewFileType = "Excel Files 1997-2003 (*.xls), *.xls," & _
"Excel Files 2007 (*.xlsx), *.xlsx," & _
"All files (*.*), *.*"[/b]
[b]NewFile = Application.GetSaveAsFilename( _
InitialFileName:=NewFileName, _
fileFilter:=NewFileType)[/b]
If NewFile <> "" And NewFile <> "False" Then
[b] ActiveWorkbook.SaveAs Filename:= NewFile, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
ReadOnlyRecommended:=False, _
CreateBackup:=False
[/b]
Set ActBook = ActiveWorkbook
Workbooks.Open CurrentFile
ActBook.Close
End If
Application.ScreenUpdating = True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
You can save this to a variable:
Open in new window
And then run whatever validation you want against "NewName"
Open in new window
Edited: Fixed my script error