Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default SaveAs Issues

Here is my macro, pulled from elsewhere in this discussion group:

Sub saveascsv()

Dim SaveName
SaveName = ThisWorkbook.Path & "\CSV Output.csv"

Worksheets("Summary").Activate
Worksheets.Copy
Workbooks(Workbooks.Count).Activate
Workbooks(Workbooks.Count).SaveAs SaveName, xlCSV,
ConflictResolution:=xlLocalSessionChanges
Workbooks(Workbooks.Count).Close SaveChanges:=False

End Sub

My questions:
1. How do I "trap" the error whenever a prior version of "CSV Output" is
open? I'm thinking of a user msg such as "Please close CSV Ouput and try
again" with a Retry button.
2. How do I avoid the user being asked if s/he wants to overwrite an
existing version of the file? In this particular application, it is never
wrong to do so. The above code doesn't work.

Many thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SaveAs Issues

The easy question first:

#2. You can use application.displayalerts = false, do the save, and then turn
it back to True. This will avoid the "wanna overwrite" prompt.

#1. I'd try the save and report the error if there is one.

Combined:

Option Explicit
Sub saveascsv()

Dim SaveName As String
SaveName = ThisWorkbook.Path & "\CSV Output.csv"

Worksheets("Summary").Copy 'to a new workbook

With ActiveWorkbook
Application.DisplayAlerts = False
On Error Resume Next
.SaveAs Filename:=SaveName, FileFormat:=xlCSV
If Err.Number < 0 Then
MsgBox "File Not Saved" & vbLf & _
Err.Number & "--" & Err.Description
Err.Clear
End If
On Error GoTo 0
Application.DisplayAlerts = True
.Close savechanges:=False
End With

End Sub



John V wrote:

Here is my macro, pulled from elsewhere in this discussion group:

Sub saveascsv()

Dim SaveName
SaveName = ThisWorkbook.Path & "\CSV Output.csv"

Worksheets("Summary").Activate
Worksheets.Copy
Workbooks(Workbooks.Count).Activate
Workbooks(Workbooks.Count).SaveAs SaveName, xlCSV,
ConflictResolution:=xlLocalSessionChanges
Workbooks(Workbooks.Count).Close SaveChanges:=False

End Sub

My questions:
1. How do I "trap" the error whenever a prior version of "CSV Output" is
open? I'm thinking of a user msg such as "Please close CSV Ouput and try
again" with a Retry button.
2. How do I avoid the user being asked if s/he wants to overwrite an
existing version of the file? In this particular application, it is never
wrong to do so. The above code doesn't work.

Many thanks.


--

Dave Peterson
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
SaveAs - VBA Jae Excel Discussion (Misc queries) 0 April 10th 08 06:04 AM
VBA SaveAs Value charlie Excel Discussion (Misc queries) 4 August 27th 07 11:33 PM
SaveAs Duncan[_6_] Excel Programming 1 June 15th 06 09:52 AM
saveas Nikita Excel Programming 1 September 17th 03 02:39 AM
SaveAs Darrin Henry Excel Programming 0 September 12th 03 10:09 PM


All times are GMT +1. The time now is 10:25 AM.

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

About Us

"It's about Microsoft Excel"