PC Review


Reply
Thread Tools Rate Thread

Command Button to export a worksheet as a .csv file

 
 
Ormond
Guest
Posts: n/a
 
      8th May 2009
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 With Quote
 
 
 
 
Ormond
Guest
Posts: n/a
 
      8th May 2009
Thanks. I added the following code to get me back to the worksheet that I
started at:

Worksheets("YourSpecialSheetName").Activate

I've added a few extra keywords so this might help other people searching
for answers
KEYWORDS: SaveAs Method, text file, comma delimited file,

"Nigel" wrote:

> At the end of your code add this........
>
> ActiveWorkbook.Close savechanges:=False
>
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "Ormond" <(E-Mail Removed)> wrote in message
> news:5EE5D581-F328-4C85-B411-(E-Mail Removed)...
> >I made a mistake on the copy/paste of the code... the code that I have is
> >as
> > follows:
> >
> > 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:="", _
> > ReadOnlyRecommended:=False, CreateBackup:=False
> > End Sub
> >
> > Where "MySheet" is the worksheet that gets saved to a .csv file
> >
> > "Ormond" wrote:
> >
> >> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Command Button to export a worksheet as a .csv file Ormond Microsoft Excel Programming 1 8th May 2009 07:56 AM
Command button to export data to Excel Beth Microsoft Access Form Coding 0 16th Jan 2007 05:40 PM
Command Button on worksheet Jack Microsoft Excel Programming 4 12th Jun 2006 11:51 AM
Using command button in a form to export a report Alex Martinez Microsoft Access Form Coding 1 22nd Mar 2006 12:56 PM
Export to Excel Command button Bill Microsoft Access Form Coding 0 26th Apr 2005 12:51 AM


Features
 

Advertising
 

Newsgroups
 


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