31-01-2011, 11:52
Elimde aşağıda gördüğünüz dosya ismini formdaki bir unbound text box'a kaydeden bir kod mevcut. Bu kodu modBrwsforXLS adıyla bir modül olarak kayıt ettim. (Kod test modunda çalışıyor.)
Sorum ise bu modüldeki GetOpenFile isimli Function'ı formdaki bir butonla nasıl ilişkilendirebilirim? (On Click)
Sorum ise bu modüldeki GetOpenFile isimli Function'ı formdaki bir butonla nasıl ilişkilendirebilirim? (On Click)
Visual Basic
- Option Compare Database
-
- ' This code was originally written by Ken Getz.
- ' It is not to be altered or distributed, 'except as part of an application.
- ' You are free to use it in any application,
- ' provided the copyright notice is left unchanged.
- '
- ' Code originally courtesy of:
- ' Microsoft Access 95 How-To
- ' Ken Getz and Paul Litwin
- ' Waite Group Press, 1996
- ' Revised to support multiple files:
- ' 28 December 2007
-
- Type tagOPENFILENAME
- lStructSize As Long
- hwndOwner As Long
- hInstance As Long
- strFilter As String
- strCustomFilter As String
- nMaxCustFilter As Long
- nFilterIndex As Long
- strFile As String
- nMaxFile As Long
- strFileTitle As String
- nMaxFileTitle As Long
- strInitialDir As String
- strTitle As String
- Flags As Long
- nFileOffset As Integer
- nFileExtension As Integer
- strDefExt As String
- lCustData As Long
- lpfnHook As Long
- lpTemplateName As String
- End Type
-
- Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
- Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean
-
- Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _
- Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As Boolean
- Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
-
- Global Const ahtOFN_READONLY = &H1
- Global Const ahtOFN_OVERWRITEPROMPT = &H2
- Global Const ahtOFN_HIDEREADONLY = &H4
- Global Const ahtOFN_NOCHANGEDIR = &H8
- Global Const ahtOFN_SHOWHELP = &H10
- ' You won't use these.
- 'Global Const ahtOFN_ENABLEHOOK = &H20
- 'Global Const ahtOFN_ENABLETEMPLATE = &H40
- 'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80
- Global Const ahtOFN_NOVALIDATE = &H100
- Global Const ahtOFN_ALLOWMULTISELECT = &H200
- Global Const ahtOFN_EXTENSIONDIFFERENT = &H400
- Global Const ahtOFN_PATHMUSTEXIST = &H800
- Global Const ahtOFN_FILEMUSTEXIST = &H1000
- Global Const ahtOFN_CREATEPROMPT = &H2000
- Global Const ahtOFN_SHAREAWARE = &H4000
- Global Const ahtOFN_NOREADONLYRETURN = &H8000
- Global Const ahtOFN_NOTESTFILECREATE = &H10000
- Global Const ahtOFN_NONETWORKBUTTON = &H20000
- Global Const ahtOFN_NOLONGNAMES = &H40000
- ' New for Windows 95
- Global Const ahtOFN_EXPLORER = &H80000
- Global Const ahtOFN_NODEREFERENCELINKS = &H100000
- Global Const ahtOFN_LONGNAMES = &H200000
- Function GetOpenFile(Optional varDirectory As Variant, _
- Optional varTitleForDialog As Variant) As Variant
-
- ' Here's an example that gets an Access database name.
- Dim strFilter As String
- Dim lngFlags As Long
- Dim varFileName As Variant
-
- ' Specify that the chosen file must already exist,
- ' don't change directories when you're done
- ' Also, don't bother displaying
- ' the read-only box. It'll only confuse people.
- lngFlags = ahtOFN_FILEMUSTEXIST Or _
- ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
- If IsMissing(varDirectory) Then
- varDirectory = ""
- End If
- If IsMissing(varTitleForDialog) Then
- varTitleForDialog = ""
- End If
-
- ' Define the filter string and allocate space in the "c"
- ' string Duplicate this line with changes as necessary for
- ' more file templates.
- strFilter = ahtAddFilterItem(strFilter, _
- "Excel File (*.xlsx)", "*.xlsx;*.xls")
-
- ' Now actually call to get the file name.
- varFileName = ahtCommonFileOpenSave( _
- OpenFile:=True, _
- InitialDir:=varDirectory, _
- Filter:=strFilter, _
- Flags:=lngFlags, _
- DialogTitle:=varTitleForDialog)
- If Not IsNull(varFileName) Then
- varFileName = TrimNull(varFileName)
- End If
- GetOpenFile = varFileName
- Forms!frm_File_Tools![Text3] = varFileName
- End Function
- Private Function TrimNull(ByVal strItem As String) As String
- Dim intPos As Integer
-
- intPos = InStr(strItem, vbNullChar)
- If intPos > 0 Then
- TrimNull = Left(strItem, intPos - 1)
- Else
- TrimNull = strItem
- End If
- End Function
- Private Function FixPath(ByVal path As String) As String
- If Right$(path, 1) <> "\" Then
- FixPath = path & "\"
- Else
- FixPath = path
- End If
- End Function

