ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can error 1004 be trapped???? (https://www.excelbanter.com/excel-programming/283898-can-error-1004-trapped.html)

Richard m

Can error 1004 be trapped????
 

I am still having a problem with trapping error 1004. Again I have cod
saving the spreadsheet as SaveAs, but when I select no of cancel, I ge
the end debug error 1004.

I have posted this several days ago with code and pulling hair out.

Los

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com


Colo[_2_]

Can error 1004 be trapped????
 

Hi Richard,

You can trap error with "On Error" method.
Please look into "On error resume next" in your VBE help.


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/


shockley

Can error 1004 be trapped????
 
Richard,

Try this modification to your code (below).

HTH,
Shockley



Sub Macro3()

Dim ans As String
Dim ans2 As String
Dim number

ans = "C:\" & Range("playsave").Value
ans2 = Range("playsave").Value & ".xls"

'There are better ways of checking whether a directory
exists!
On Error Resume Next
MkDir ans
On Error GoTo 0

ChDir ans

'Tests for existence of file in current directory:
sTest = Dir(ans & "\" & ans2)

'Saves the file if it doesn't already exist:
If sTest = "" Then
ActiveWorkbook.SaveAs FileName:=ans & "\" & ans2

'Replaces the file only if "yes" is selected from the
message box:
Else
bTest = MsgBox("A file named " & sTest & " already exists in this
location. " & _
"Do you wish to replace it?", 4)
If bTest = 6 Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=ans & "\" & ans2
Application.DisplayAlerts = True
End If
End If
End Sub




"Richard m" wrote in message
...

I am still having a problem with trapping error 1004. Again I have code
saving the spreadsheet as SaveAs, but when I select no of cancel, I get
the end debug error 1004.

I have posted this several days ago with code and pulling hair out.

Lost


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Richard m

Can error 1004 be trapped????
 

Hello shockley,

I will be trying this code a little bit latter in the day. A couple o
questions pops up after reading the code.

on error resume next -- Don't really understand how this works but
will I will be reading up on this and on error goto 0.

Found out after the post that the path I am looking for is c:\folder1
and then I will write to c:\folder1\playsave\*.xls. I will have t
create the playsave folder if it does not exist. If it is not on
drive then the path is d:\folder1.

Thanks for the help in code. I sure enjoy this forum.

Richard

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com



All times are GMT +1. The time now is 06:59 AM.

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