VBA code for Excel File Save As
Hi khlaudhya,
If mRateName and Validade are strings, you need to enclose them with double
quotes.
Similarly, you need to enclose the title argument (Save) of the msgbox in
quotes. You also need to provide an End If to close your If clause.
Incorporating thesr changes your code works for me and becomes:
Sub Test
Dim NewName As String
NewName = "mratename" & " " & "Validade" & ".xls"
If MsgBox("Save file as " & NewName & "?", vbYesNo, "Save") = vbNo Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=NewName
End Sub
The new file will be saved your default file location. If you wish to save
to another folder, simply prefix NewName with the full folder path.
---
Regards,
Norman
"khlaudhya" wrote in message
...
Hi,
I'm building a code where at some point I need to save the file to a new
location with a specific file name, which is also specified by the code. I
would like to be prompted for this but it only saves if I specify the path.
This is the bit I have already written and can't go further:
Dim NewName As String
NewName = mRateName & " " & Validade & ".xls"
If MsgBox("Save file as " & NewName & "?", vbYesNo, Save) = vbNo Then
Exit Sub
ActiveWorkbook.SaveAs FileName:=NewName
Can anyone help me?
Thanks
|