PDA

View Full Version : How to save an SQL file using Save Dialog in excel



szcukg
09-07-2010, 12:53 PM
I'm creating an SQL file using Application.Path & SQL_statements.After that I write SQL statements into this file through vba.Now I want to save the file after all SQL statements are generated in an different directory.This directory depends upon the user.Hence I want to give him an Save as Dialog .


Thus, I need to save the file that I created through vba, and save it using save as dialog in a location specified by the user and delete the copy of file created by me.

slamet Harto
09-07-2010, 02:11 PM
Application.Dialogs(xlDialogSaveAs).Show

Kenneth Hobs
09-07-2010, 08:12 PM
You can adapt this. Sub Test()
MsgBox FileOpen("x:\", "Ken Files", "*Ken*.xls")
End Sub


Function FileOpen(initialFilename As String, _
Optional sDesc As String = "Excel (*.xls)", _
Optional sFilter As String = "*.xls") As String
With Application.FileDialog(msoFileDialogOpen)
.ButtonName = "&Open"
.initialFilename = initialFilename
.Filters.Clear
.Filters.Add sDesc, sFilter, 1
.Title = "File Open"
.AllowMultiSelect = False
If .Show = -1 Then FileOpen = .SelectedItems(1)
End With
End Function

szcukg
09-07-2010, 09:57 PM
I already have a file created.What I want to do is when the user specifies a file name and location using dialog box I want to copy the contents of my file in user specified location and then kill my file.How do I copy.

Bob Phillips
09-08-2010, 12:31 AM
Name old_file As new_file


no need to kill it as it gets renamed.