Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Allowing User to save file

I have an application that we copy information into and then need to save it
as a CSV file. I have written the simple code below that does exactly what I
need it to. The user does not need to have the current file or the saved
file open when completed. I have a button they click and the file saves and
closes.

Can anyone tell me how to change to code to allow the user to pick the name
and path of where they would like it to be saved? The way I have it setup if
the path does not exist I get an error.

Also, if the file they were coping from was open and always the same name is
there a way I could get this file to copy the information and paste it. I
would also need to have some type of if error resume so if they did not have
the file open.

Any help will be appreciated.

Private Sub United_Click()
Sheets("Census Data").Select
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Documents and
Settings\Cindy\Desktop\Census Export Files\United.csv", FileFormat _
:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Allowing User to save file

Dim sFilename as string

sFilename = Application.GetOpenFilename()
If sFilename = False Then Exit Sub

Sheets("Census Data").Select
Application.DisplayAlerts = False
With ActiveWorkbook
.SaveAs Filename:=sFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
End with

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Allowing User to save file

This is probably more accurate (and easier!) than the last one I
posted:

Sheets("Census Data").Select
Application.DisplayAlerts = False
Application.Dialogs(xlDialogSaveAs).Show
ActiveWorkbook.Close

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Allowing User to save file

Kletcho:

Thank you so much for your reply. I got the first one and couldnt get it to
work but the second one works like a charm.

Is there anything I can add to the code to make it default to saving it as a
CSV file.

Thanks again for all your help.

"Kletcho" wrote:

This is probably more accurate (and easier!) than the last one I
posted:

Sheets("Census Data").Select
Application.DisplayAlerts = False
Application.Dialogs(xlDialogSaveAs).Show
ActiveWorkbook.Close


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Allowing User to save file

No problemo. Sorry I mislead you at first. You can change the file
type by changing this line to:

Application.Dialogs(xlDialogSaveAs).Show "", 6

The arguments for this command as found in VBA help a

xlDialogSaveAs - document_text, type_num, prot_pwd, backup,
write_res_pwd, read_only_rec

So in this case the document name is blank and the type_num is 6 which
means a CSV file.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Allowing User to save file

Thank you so much. I actually found information in the help files but just
didnt understand it. This has been very helpful. Thanks again.

"Kletcho" wrote:

No problemo. Sorry I mislead you at first. You can change the file
type by changing this line to:

Application.Dialogs(xlDialogSaveAs).Show "", 6

The arguments for this command as found in VBA help a

xlDialogSaveAs - document_text, type_num, prot_pwd, backup,
write_res_pwd, read_only_rec

So in this case the document name is blank and the type_num is 6 which
means a CSV file.


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
Excel File says locked by My User ID - Can't Save kristen0316 Excel Worksheet Functions 1 February 23rd 07 06:00 PM
User defined file name on save Jim G Excel Discussion (Misc queries) 11 October 30th 06 01:29 AM
How do I suppress user dialog in File Save As? Tony Lin[_2_] Excel Programming 1 March 29th 06 08:56 AM
User cannot save excel file in workbook Justin@Martin Excel Worksheet Functions 0 May 16th 05 01:52 PM
Prompt user to save their file Sharon[_5_] Excel Programming 4 September 29th 03 09:44 PM


All times are GMT +1. The time now is 09:16 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"