Customizing the TransferSpreadsheet Code

andrewghunt

Registered User.
Local time
Today, 17:26
Joined
Jan 16, 2009
Messages
10
Hi, I have the code TransferSpreadsheet running in one of my forms to export to Excel, is it possible to specify the file name and directory you wish to export it to each time, instead of specifying the directory and file name in the Macro?
Thanks
 
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "MyTableName", "C:\MyFolder\MyExcelFile.xls"
 
Sorry, what I meant was I have that kind of thing now, but I want the user to be able to customize the destination and file name each time they export, without changing the code. Can that be done?
 
substitute the bold bits above with variables

then use a file picker etc, or a drop down to pick the variables
 
Code:
[COLOR="Navy"]Dim[/COLOR] objFileDialog [COLOR="navy"]As[/COLOR] FileDialog

[COLOR="navy"]Set[/COLOR] objFileDialog = Application.FileDialog(msoFileDialogSaveAs)

objFileDialog.Show

[COLOR="DarkGreen"]' NOTE: Substitute "MyTableName" with actual table name[/COLOR]
[COLOR="Navy"]If[/COLOR] objFileDialog.SelectedItems.Count = 1 [COLOR="navy"]Then[/COLOR]
    DoCmd.TransferSpreadsheet acExport, _
        acSpreadsheetTypeExcel9, _
        "MyTableName", objFileDialog.SelectedItems(1)
[COLOR="navy"]End If[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom