Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Command Button to export a worksheet as a .csv file

I'd like to make a command button that will export a specific worksheet as a
..csv file. Upon clicking the button, I'd like a prompt for the file name,
then once I've saved the file I'd like to be back on the worksheet where I
started.

I've pasted together some code from other questions and I've almost got what
I want, but it doesn't quite work. The code below will save the worksheet as
a .csv file. But the new file remains open and active. I'd like the new
file to be closed after I save it and I'd like to be back at the worksheet
where I started in the original workbook. I'd appreciate any suggestions

Private Sub CommandButton1_Click()
Sheets("MySheet").Select
Sheets("MySheet").Copy
Do
fName = Application.GetSaveAsFilename
Loop Until fName < False
ActiveWorkbook.SaveAs Filename:=fName, _
FileFormat:=xlCSV, Password:="", WriteResPassword:="", _
End Sub

Where "MySheet" is the sheet that gets saved as a .csv file.
ReadOnlyRecommended:=False, CreateBackup:=False
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
Command Button to export a worksheet as a .csv file Ormond[_2_] Excel Programming 1 May 8th 09 07:56 AM
Command Button On A Worksheet Steve[_91_] Excel Programming 3 September 6th 07 09:18 AM
Command button on worksheet Dale Fye Excel Programming 4 August 22nd 07 03:00 PM
Command Button on worksheet Jack Excel Programming 4 June 12th 06 11:51 AM
command button on worksheet PhilC Excel Programming 1 May 19th 06 05:09 PM


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

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"