ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stopping error (https://www.excelbanter.com/excel-programming/360523-stopping-error.html)

XCESIV[_12_]

Stopping error
 

Below is a macro i have made that saves the file name like i want it too
using data from the worksheet. The problem is if they file name has
been used before, which it shouldnt have but could have accidently been
saved, it asks if you would like to save over this. if you click no
then it crashes.

Is it possible to set it that if u click no it just ends the macro.

thanks

Sub SAVEAS_NEW_FNE()
Dim FN As Workbook
Dim D As Variant
[D] = Format(Range("B3"), "mm_dd_yyyy")
ThisWorkbook.SaveAs Filename:="FNE " & [D]
End Sub


--
XCESIV
------------------------------------------------------------------------
XCESIV's Profile: http://www.excelforum.com/member.php...o&userid=24271
View this thread: http://www.excelforum.com/showthread...hreadid=538749


Ivan Raiminius

Stopping error
 
Hi,

if you want simply prevent raising error use on error resume next.

Better way is to check if the filename is already used, have a look at:

http://www.j-walk.com/ss/excel/tips/tip54.htm

regards,
Ivan


Bob Phillips[_14_]

Stopping error
 
Sub SAVEAS_NEW_FNE()
Dim FN As Workbook
Dim D As Variant
Dim sFilename As String

[D] = Format(Range("B3"), "mm_dd_yyyy")
sFilename ="FNE " & [D]
If Len(Dir(sFilename)) = 0 Then
ThisWorkbook.SaveAs Filename:="FNE " & [D]
Else
Msgbox sFilename & " already exists"
End If
End Sub


--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"XCESIV" wrote in
message ...

Below is a macro i have made that saves the file name like i want it too
using data from the worksheet. The problem is if they file name has
been used before, which it shouldnt have but could have accidently been
saved, it asks if you would like to save over this. if you click no
then it crashes.

Is it possible to set it that if u click no it just ends the macro.

thanks

Sub SAVEAS_NEW_FNE()
Dim FN As Workbook
Dim D As Variant
[D] = Format(Range("B3"), "mm_dd_yyyy")
ThisWorkbook.SaveAs Filename:="FNE " & [D]
End Sub


--
XCESIV
------------------------------------------------------------------------
XCESIV's Profile:

http://www.excelforum.com/member.php...o&userid=24271
View this thread: http://www.excelforum.com/showthread...hreadid=538749




XCESIV[_13_]

Stopping error
 

in a macro i have i open a 2nd workbook. when i try and get the macro
to close the file it asks to save yes/no

is there a way to stop it asking this question

Thanks


--
XCESIV
------------------------------------------------------------------------
XCESIV's Profile: http://www.excelforum.com/member.php...o&userid=24271
View this thread: http://www.excelforum.com/showthread...hreadid=538749


Bob Phillips[_14_]

Stopping error
 
Use

Use the SaveChanges:=False option on the close.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"XCESIV" wrote in
message ...

in a macro i have i open a 2nd workbook. when i try and get the macro
to close the file it asks to save yes/no

is there a way to stop it asking this question

Thanks


--
XCESIV
------------------------------------------------------------------------
XCESIV's Profile:

http://www.excelforum.com/member.php...o&userid=24271
View this thread: http://www.excelforum.com/showthread...hreadid=538749





All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com