"另存为..."对话框中MSACCESS VBA:怎么了? [英] "Save as..." dialog box in MSAccess vba: how?
问题描述
在MSACCESS我有一个按钮的面具。当用户点击该按钮时,在一个表中的数据导出上.txt文件:
In MSAccess I've a mask with a button. When the user clicks on the button, the data in a table are exported on a .txt file:
Private Sub Command_Click()
Dim Rst As DAO.Recordset
Dim AField As DAO.Field
Dim TempStr As String
Dim FileNumber
FileNumber = FreeFile
Open "c:\table.txt" For Output As #FileNumber
Set Rst = CurrentDb.OpenRecordset("Tabella1", dbOpenForwardOnly)
Do While Not Rst.EOF
For Each AField In Rst.Fields
If (AField.Name <> "ID") Then
TempStr = TempStr & AField.value & " "
End If
Next
Print #FileNumber, Left(TempStr, Len(TempStr) - 1)
TempStr = ""
Rst.MoveNext
Loop
Rst.Close
Set Rst = Nothing
Close #FileNumber
End Sub
它的工作原理,但我会通过允许用户选择其上导出数据的文件显示一个另存为...对话框。
It works, but I would display a "Save as..." dialog box by allowing the user to choose the file on which export the data.
这可能吗?
推荐答案
您可以设置引用到Microsoft Office XX对象库,并使用FileDialog的。
You can set a reference to the Microsoft Office x.x Object Library and use FileDialog.
Sub ShowFileDialog()
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogSaveAs)
With dlgOpen
.InitialFileName = "Z:\docs\"
.Show
End With
End Sub
另外:<一href="http://stackoverflow.com/questions/2158675/how-do-i-get-a-single-file-name-out-of-a-file-dialog-object-in-vba-for-ms-acces/2158796#2158796">How我在VBA得到一个文件名从文件对话框的对象(的MS Access 2007)?
这篇关于&QUOT;另存为...&QUOT;对话框中MSACCESS VBA:怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!