cssfonseca
New Member
- Joined
- Aug 14, 2018
- Messages
- 19
Hi. I writing a macro to save my file and to do some procedures after it, but I ran into a little error. When I run the macro, and it asks for the file location and I escape, the macro goes to the error but it stills cleans the sheets (limpafolhas), which I don't want to, unless the saving is successful.
Basically, I want when is no error, to go to that. Can u help me out? When I'm searching for this topic I've always ended up in an On Error GoTo 0, but I think that's not what I need.
And, just a small question, to save without any macros, the file type is correct?
Basically, I want when is no error, to go to that. Can u help me out? When I'm searching for this topic I've always ended up in an On Error GoTo 0, but I think that's not what I need.
And, just a small question, to save without any macros, the file type is correct?
Code:
Sub salvar()Dim fPath As Variant
fPath = _
Application.GetSaveAsFilename(InitialFileName:=Left(ThisWorkbook.Name, _
InStr(1, ThisWorkbook.Name, ".xls") - 1), _
filefilter:="Excel Files (*.xlsx*), *.xlsx*")
'deletes all sheets except 1
limpafolhas
'unhides all rows
UnhideAll
On Error Resume Next
If fPath = False Then
MsgBox "File path not found - try again."
Exit Sub
End If
On Error GoTo 0
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=CStr(fPath) & "xls", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
End Sub