#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Save as CSV

I am trying to save a sheet to CSV file (users are free to choose the
location to save this file). I am able to do it, but when I open the
file, only the extension is CSV but the format still XLS (all formula,
, color, format still there).
Any guru can help? Thanks.

Private Sub CommandButton1_Click()

On Error GoTo errHandler:

Application.EnableEvents = False
Application.ScreenUpdating = False

Dim mysave, filesavename, myLocation, myFileName
Dim Cancel As Boolean

myFileName = Sheet1.Range("B4") & Sheet1.Range("B1")
mysave = MsgBox("Please chose location to save CSV file!", vbOKCancel)

If mysave = vbCancel Then
GoTo errHandler
End If

Sheets("Section").Select
ActiveSheet.Copy

SavingFile:

filesavename = Application.GetSaveAsFilename(myFileName, _
fileFilter:="CSV (Comma Delimited) (*.csv), *.csv")

If filesavename < False Then
Application.DisplayAlerts = False
Dim resp As Long
resp = vbYes
If Dir(filesavename) < "" Then
resp = MsgBox(Prompt:=filesavename & " already exist,
overwrite?", Buttons:=vbYesNo)
End If

If resp = vbYes Then
ActiveWorkbook.SaveAs filesavename
myLocation = ActiveWorkbook.Path
ActiveWorkbook.Close
MsgBox (myFileName & ".csv was saved in " & myLocation)
Sheets("Department").Select
Application.EnableEvents = True
Application.DisplayAlerts = True
Else
GoTo SavingFile
End If

Else
Cancel = True
Application.DisplayAlerts = False
ActiveWorkbook.Close
Sheets("Department").Select
GoTo errHandler
End If

errHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.StatusBar = False
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Save as CSV

Take a look at the SaveAs method in XL/VBA Help.

You need to use the fileformat argument...



In article .com,
"broogle" wrote:

I am trying to save a sheet to CSV file (users are free to choose the
location to save this file). I am able to do it, but when I open the
file, only the extension is CSV but the format still XLS (all formula,
, color, format still there).

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
Save, save as, page setup dimmed out in unprotected excel sheet? ccKeithJ Excel Discussion (Misc queries) 3 December 14th 07 07:07 PM
SAVE and SAVE AS options disappeared from the drop down FILE menu [email protected] Excel Discussion (Misc queries) 2 July 12th 07 09:14 AM
Save As and save current numbers not the actual formulas and links Frank Menard Excel Discussion (Misc queries) 2 November 9th 06 09:18 PM
Save Excel file - prompts to save - no Volitile functions used POWER CERTS Excel Worksheet Functions 2 November 1st 04 09:27 PM
Save As - Multiple Sheets fails to save as text file Ravee Srinivasan Excel Programming 2 November 10th 03 04:05 PM


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

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"