Renato_POA 3/11/2011, 19:30
Pode-se utilizar a seguinte função:
'Abre a caixa de Dialogo para localizar arquivo
'Cortesia: Carlos Moura - www.espacoaccess.com
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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
Public Function LocalizarArquivo(strDirIni As String) ', strTitulo As String, strFiltro As String)
On Error Resume Next
Dim OpenFile As OPENFILENAME
Dim lReturn As Long, pos As Long
OpenFile.lStructSize = Len(OpenFile)
'OpenFile.lpstrFilter = strFiltro
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = strDirIni
'OpenFile.lpstrTitle = strTitulo
OpenFile.Flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
LocalizarArquivo = ""
Else
pos = InStr(1, OpenFile.lpstrFile, Chr(0))
If pos > 0 Then
LocalizarArquivo = Left(OpenFile.lpstrFile, pos - 1)
Else
LocalizarArquivo = OpenFile.lpstrFile
End If
End If
End Function
'Sub de chamada para
'atribuir caminho do arquivo à caixa de texto 'Arquivo'.
Private Sub Btn_Arquivo_Click()
On Error GoTo Trata_Erro
Me!Arquivo = LocalizarArquivo("C:\TEMP")
Exit Sub
Trata_Erro:
MsgBox Err.Description
End Sub
Qualquer dúvida, favor entrar em contato.