First of all, the "CommonDialog Class" doesn t even appear to work on a 32-bit version of Office. It gives the same OleDb error. As one of the commenters points out, this isn t the control you should be using. And while there might be another ActiveX control you could use, there s really no guarantee that it will be available on every machine that you want to deploy your database on. My dev box has Visual Studio 6, VS 2008, and VS 2010 on it, in addition to Office and other programs, all of which provide ActiveX DLLs that a typical user could not be expected to have. Additionally, many of these libraries are not redistributable, or pose unique installation hurdles that may simply not be worth the trouble.
www.un.org/Depts/DGACM/index_spanish.htm 到目前为止,最简单、最普遍的解决办法是把“开放方言”从“窗户”转播。 它位于 comdlg32.dll,每版本的视窗都可供选择,而且不会把任何附属于 comdlg32.ocx。 该系统还提供比使用主动X控制更好的性能,因为它没有要求增加一个模块,以装上记忆。
所需要的法典也非常复杂。 http://msdn.microsoft.com/en-us/library/ms646927.aspx” rel=“nofollow”GetOpenFileName
,创建开放方言箱。 该表仅涉及一个参数,即OPENFILENAME structure,其中载有用于启动方言箱的信息,以及接收用户选择的档案。 因此,你也需要宣布这一结构。 VBA的法典将考虑这样的内容:
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (ByRef lpofn As OPENFILENAME) As Long
另外,还有两条固定不变的标志,可以把直言语当作特定行为。 完整无遗,此处列出完整清单:
Private Const OFN_ALLOWMULTISELECT As Long = &H200
Private Const OFN_CREATEPROMPT As Long = &H2000
Private Const OFN_ENABLEHOOK As Long = &H20
Private Const OFN_ENABLETEMPLATE As Long = &H40
Private Const OFN_ENABLETEMPLATEHANDLE As Long = &H80
Private Const OFN_EXPLORER As Long = &H80000
Private Const OFN_EXTENSIONDIFFERENT As Long = &H400
Private Const OFN_FILEMUSTEXIST As Long = &H1000
Private Const OFN_HIDEREADONLY As Long = &H4
Private Const OFN_LONGNAMES As Long = &H200000
Private Const OFN_NOCHANGEDIR As Long = &H8
Private Const OFN_NODEREFERENCELINKS As Long = &H100000
Private Const OFN_NOLONGNAMES As Long = &H40000
Private Const OFN_NONETWORKBUTTON As Long = &H20000
Private Const OFN_NOREADONLYRETURN As Long = &H8000&
Private Const OFN_NOTESTFILECREATE As Long = &H10000
Private Const OFN_NOVALIDATE As Long = &H100
Private Const OFN_OVERWRITEPROMPT As Long = &H2
Private Const OFN_PATHMUSTEXIST As Long = &H800
Private Const OFN_READONLY As Long = &H1
Private Const OFN_SHAREAWARE As Long = &H4000
Private Const OFN_SHAREFALLTHROUGH As Long = 2
Private Const OFN_SHAREWARN As Long = 0
Private Const OFN_SHARENOWARN As Long = 1
Private Const OFN_SHOWHELP As Long = &H10
Private Const OFS_MAXPATHNAME As Long = 260
And for convenience, I ve wrapped this whole mess inside of a helper function that you can call from within VBA. It accepts as parameters the properties you will most commonly need to set for the open file dialog, handles calling the Windows API itself, and then returns either the full path to the file selected by the user, or an empty string (vbNullString
) if the user clicked the Cancel button. You can test the return value in the calling code to determine which course of action to take.
This function shows the Windows Open File dialog with the specified
parameters, and either returns the full path to the selected file,
or an empty string if the user cancels.
Public Function OpenFile(ByVal Title As String, ByVal Filter As String, _
ByVal FilterIndex As Integer, ByVal StartPath As String, _
Optional OwnerForm As Form = Nothing) As String
Create and populate an OPENFILENAME structure
using the specified parameters
Dim ofn As OPENFILENAME
With ofn
.lStructSize = Len(ofn)
If OwnerForm Is Nothing Then
.hwndOwner = 0
Else
.hwndOwner = OwnerForm.Hwnd
End If
.lpstrFilter = Filter
.nFilterIndex = FilterIndex
.lpstrFile = Space$(1024) & vbNullChar & vbNullChar
.nMaxFile = Len(ofn.lpstrFile)
.lpstrFileTitle = vbNullChar & Space$(512) & vbNullChar & vbNullChar
.nMaxFileTitle = Len(.lpstrFileTitle)
.lpstrInitialDir = StartPath & vbNullChar & vbNullChar
.lpstrTitle = Title
.flags = OFN_FILEMUSTEXIST
End With
Call the Windows API function to show the dialog
If GetOpenFileName(ofn) = 0 Then
The user pressed cancel, so return an empty string
OpenFile = vbNullString
Else
The user selected a file, so remove the null-terminators
and return the full path
OpenFile = Trim$(Left$(ofn.lpstrFile, Len(ofn.lpstrFile) - 2))
End If
End Function
由此而来的是漫长的。 有许多声明需要复制并贴上模块,但你实际上必须处理的接口非常简单。 这里是你在法典中如何实际利用这一工具来显示公开档案辩证,并找到档案:
Public Sub DoWork()
Set the filter string (patterns) for the open file dialog
Dim strFilter As String
strFilter = "Text Files (*.txt)" & vbNullChar & "*.txt*" & vbNullChar & _
"All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
Show the open file dialog with the custom title, the filters specified
above, and starting in the root directory of the C: drive.
Dim strFileToOpen As String
strFileToOpen = OpenFile("Choose a file to open", strFilter, 0, "C:")
See if the user selected a file
If strFileToOpen = vbNullString Then
MsgBox "The user pressed the Cancel button."
Else
MsgBox "The user chose to open the following file: " & _
vbNewLine & strFileToOpen
End If
End Sub
<><>> 撰写和测试这一解决办法的最长部分实际上试图找到如何向世贸总会编辑开放和撰写进入的宏观文件。 Ribbon可能是一种伟大的发明,对使用菜单的人来说,是“Paste”和“Save”的。 我每天使用软件,我仍然无法发现。 [/rant]