Dim Spreadsheet_Name As Variant
Spreadsheet_Name = Application.GetSaveAsFilename
If Spreadsheet_Name <> False Then ActiveWorkbook.SaveAs Filename:=Spreadsheet_Name
Thank youSomething like (Air code - Untested)
Code:Dim Spreadsheet_Name As Variant Spreadsheet_Name = Application.GetSaveAsFilename If Spreadsheet_Name <> False Then ActiveWorkbook.SaveAs Filename:=Spreadsheet_Name
Obviously, replace ActiveWorkbook with your Access Object reference.
Dim CSOrderlineItemsQry As Variant
CSOrderlineItemsQry = Application.GetSaveAsFilename
If CSOrderlineItemsQry <> False Then ActiveWorkbook.SaveAs FileName:=CSOrderlineItemsQry
Could you please elaborate on XLAppSorry you'll need something like
xlApp.GetSaveAsFilename
Where xlApp is your excel application object in your automation code.
Private Sub ExcelSparesforOrders__ExcelSparesforOrders_Click()
On Error GoTo ExcelSparesforOrders_Click_Err
DoCmd.OutputTo acOutputQuery, "CS Orders - Spares for Orders QRY", "Excel97-Excel2003Workbook(*.xls)", "Spares for Orders" & " - Registration -" & " " & Forms![CS Orders Detail - Main]![RegCBO] & ".xls", True, "", , acExportQualityPrint
ExcelSparesforOrders_Click_Exit:
Exit Sub
ExcelSparesforOrders_Click_Err:
MsgBox Error$
Resume ExcelSparesforOrders_Click_Exit
End Sub
Public Function strGetFileFolderName(Optional strInitialDir As String = "", Optional lngType As Long = 4, Optional strPattern As String = "All Files,*.*") As String
'StrInitialDir = where the filedialog starts browsing
'lngType e.g. 'msoFileDialogFilePicker = 3, msoFileDialogFolderPicker =4, msoFileDialogOpen=1,msoFileDialogSaveAs=2
Dim fDialog As Object
Dim vFile As Variant, varEntry As Variant
strGetFileFolderName = ""
Set fDialog = Application.FileDialog(lngType)
With fDialog
.Title = "Browse for "
Select Case lngType
Case 1 'msoFileDialogOpen
.Title = .Title & "File to open"
Case 2 'msoFileDialogSaveAs
.Title = .Title & "File to SaveAs"
Case 3 'msoFileDialogFilePicker
.Title = .Title & "File"
Case 4 'msoFileDialogFolderPicker
.Title = .Title & "Folder"
End Select
Select Case strPattern
Case "Excel"
strPattern = "MS Excel,*.XLSX; *.XLSM; *.XLS"
Case "Access"
strPattern = "MS Access,*.ACCDB"
Case "PPT"
strPattern = "MS Powerpoint,*.PPTX; *.PPTM"
End Select
If lngType <> 4 Then
'Reset then add filter patterns separated by tildes (~) where
' multiple extensions are separated by semi-colons (;) and the
' description is separated from them by a comma (,).
' Example strPattern :
' "MS Access,*.ACCDB; *.MDB~MS Excel,*.XLSX; *.XLSM; *.XLS"
Call .Filters.Clear
For Each varEntry In Split(strPattern, "~")
Call .Filters.Add(Description:=Split(varEntry, ",")(0), _
Extensions:=Split(varEntry, ",")(1))
Next varEntry
End If
'Set some default settings
.InitialFileName = strInitialDir
.AllowMultiSelect = False
.InitialView = 2 'msoFileDialogViewDetails
'Only return a value from the FileDialog if not cancelled.
If .Show Then strGetFileFolderName = .SelectedItems(1)
End With
ExitHere:
Exit Function
HandleErrors:
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
Resume ExitHere
End Function
strFileName = strGetFileFolderName(, 2, "Excel")
qryName = "CS Orders - Spares for Orders QRY"
DoCmd.TransferSpreadsheet acExport, 10, qryName, strSaveFile, True, , True
Hi,Have you tried TransferSpreadsheet? It doesn't open Excel.
I get an error on Call. Filters.clearAh - I had assumed you were doing the export in a different way.
The code below opens a file dialog and lets you choose a folder or a file, it returns the full path to whichever you use.
So you would assign a variable (Lets say strFileName) to the result of the function then use that in place of your file name.Code:Public Function strGetFileFolderName(Optional strInitialDir As String = "", Optional lngType As Long = 4, Optional strPattern As String = "All Files,*.*") As String 'StrInitialDir = where the filedialog starts browsing 'lngType e.g. 'msoFileDialogFilePicker = 3, msoFileDialogFolderPicker =4, msoFileDialogOpen=1,msoFileDialogSaveAs=2 Dim fDialog As Object Dim vFile As Variant, varEntry As Variant strGetFileFolderName = "" Set fDialog = Application.FileDialog(lngType) With fDialog .Title = "Browse for " Select Case lngType Case 1 'msoFileDialogOpen .Title = .Title & "File to open" Case 2 'msoFileDialogSaveAs .Title = .Title & "File to SaveAs" Case 3 'msoFileDialogFilePicker .Title = .Title & "File" Case 4 'msoFileDialogFolderPicker .Title = .Title & "Folder" End Select Select Case strPattern Case "Excel" strPattern = "MS Excel,*.XLSX; *.XLSM; *.XLS" Case "Access" strPattern = "MS Access,*.ACCDB" Case "PPT" strPattern = "MS Powerpoint,*.PPTX; *.PPTM" End Select If lngType <> 4 Then 'Reset then add filter patterns separated by tildes (~) where ' multiple extensions are separated by semi-colons (;) and the ' description is separated from them by a comma (,). ' Example strPattern : ' "MS Access,*.ACCDB; *.MDB~MS Excel,*.XLSX; *.XLSM; *.XLS" Call .Filters.Clear For Each varEntry In Split(strPattern, "~") Call .Filters.Add(Description:=Split(varEntry, ",")(0), _ Extensions:=Split(varEntry, ",")(1)) Next varEntry End If 'Set some default settings .InitialFileName = strInitialDir .AllowMultiSelect = False .InitialView = 2 'msoFileDialogViewDetails 'Only return a value from the FileDialog if not cancelled. If .Show Then strGetFileFolderName = .SelectedItems(1) End With ExitHere: Exit Function HandleErrors: MsgBox "Error: " & Err.Description & " (" & Err.Number & ")" Resume ExitHere End Function
I then would use something like
(Slightly Aircode you would need to dim these variables etc.)
Code:strFileName = strGetFileFolderName(, 2, "Excel") qryName = "CS Orders - Spares for Orders QRY" DoCmd.TransferSpreadsheet acExport, 10, qryName, strSaveFile, True, , True
Hopefully that will point you in the right direction
Am i using the syntax incorrectly as I am getting an errorCall is used optionally when executing procedures and functions. Filters.Clear is an internal method. It is not a procedure.
Not to me it does?Am i using the syntax incorrectly as I am getting an error
I checked, Call .Filter seems correct
.Filters.Clear
I did use Call .Filters.clearNot to me it does?
I would have thought in your context that you would use
Same with the .Add ?Code:.Filters.Clear
Where did you check for that syntax???
So have you noticed that filters has not changed to Filters ?I did use Call .Filters.clear
Please refer to the code provided in post 8 and my reply in post 11
View attachment 92825