Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code to save gives error 1004???


I have the following code that creates a folder then saves th
spreadsheet with the same name that is in A1. The problem I have is ho
to handle the error message when I save the same file again and selec
the NO option (Yes to replace works fine)and get the error code 100
that wants me to end or debug. Here is the code: The case statemen
did not work. Can I have the saveas dialog box appear on error 1004?

error is at the Activeworkbook..........


Code
-------------------

Sub Macro2()
On Error GoTo Errhandler
' Macro2 Macro
' Macro recorded 11/24/2003 by na
'
Dim ans As String
Dim ans2 As String
Dim number
ans = "C:\" & Range("playsave").Value
ans2 = Range("playsave").Value & ".xls"
MkDir ans 'makes new folder
saveitnow:

ChDir ans 'sets path to new folder

ActiveWorkbook.SaveAs Filename:=ans & "\" & ans2, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

Exit Sub
Errhandler:
Select Case Err.number ' Evaluate error number.
Case 1004 ' "File already open" error.
MsgBox "OK"
Resume saveitnow
Case Else

GoTo saveitnow 'takes care of error from when folder already
End Select

exists.



End Sub


-------------------


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default VBA code to save gives error 1004???

Try adding these lines to your code


Application.DisplayAlerts = False 'turns off error checking

ActiveWorkbook.SaveAs Filename:=ans & "\" & ans2, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

Application.DisplayAlerts = False 'turns error checking back on


D.S.


"Richard m" wrote in message ...

I have the following code that creates a folder then saves the
spreadsheet with the same name that is in A1. The problem I have is how
to handle the error message when I save the same file again and select
the NO option (Yes to replace works fine)and get the error code 1004
that wants me to end or debug. Here is the code: The case statement
did not work. Can I have the saveas dialog box appear on error 1004?

error is at the Activeworkbook..........


Code:
--------------------

Sub Macro2()
On Error GoTo Errhandler
' Macro2 Macro
' Macro recorded 11/24/2003 by na
'
Dim ans As String
Dim ans2 As String
Dim number
ans = "C:\" & Range("playsave").Value
ans2 = Range("playsave").Value & ".xls"
MkDir ans 'makes new folder
saveitnow:

ChDir ans 'sets path to new folder

ActiveWorkbook.SaveAs Filename:=ans & "\" & ans2, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

Exit Sub
Errhandler:
Select Case Err.number ' Evaluate error number.
Case 1004 ' "File already open" error.
MsgBox "OK"
Resume saveitnow
Case Else

GoTo saveitnow 'takes care of error from when folder already
End Select

exists.



End Sub


--------------------



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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime error code 1004 Karen Excel Worksheet Functions 1 May 13th 10 12:21 AM
Error Code 1004 when exporting from VB app to Excel 2007 sue mac Excel Discussion (Misc queries) 0 September 11th 07 08:10 AM
Runtime error '1004' General ODBC error star_lucas New Users to Excel 0 August 29th 05 04:09 PM
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 09:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"