ciao mi serve un consiglio su come correggere un errore su Filedialog, in pratica io vorrei selezionare un file tramite finestra di ialogo e scrivere la sua path su un campo maschera.
il codice è il seguente:
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.InitialFileName = "C:"
.Title = "Sfoglia cartelle"
.ButtonName = "Ok"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.Show
For Each objfl In .SelectedItems
filename = objfl
Next objfl
End With
NomeDirectory = filename
[Forms]![formMail2]![Testo12] = filename
end sub
mi da il messaggio necessario oggetto...
aspetto un consiglio su come fare.
ho provato anche in questo modo, ma praticamente non parte proprio la funzione, clicco sul tasto ma non fa nulla.
ho fatto un modulo standard così:
Option Compare Database
Option Explicit
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_PATHMUSTEXIST = &H800
Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (lpofn As OPENFILENAME6) As Long
Public Type OPENFILENAME6
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter 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 Sub ShowFile3(frm As Form, fb As OPENFILENAME6)
Dim fName As String
Dim result As Long
Dim Path As String
Path = "C:"
With fb
.lStructSize = Len(fb)
.hwndOwner = frm.Hwnd
.hInstance = 0
.lpstrFilter = "Tutti i file" & vbNullChar & "*.*" & vbNullChar
.nMaxCustomFilter = 0
.nFilterIndex = 1 'Default filter is the first one
.lpstrFile = Space(256) & vbNullChar d
.nMaxFile = Len(.lpstrFile)
.lpstrFileTitle = Space(256) & vbNullChar
.nMaxFileTitle = Len(.lpstrFileTitle)
.lpstrInitialDir = Path & vbNullChar
.lpstrTitle = "Apri file" & vbNullChar
.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
.nFileOffset = 0
.nFileExtension = 0
.lCustData = 0
.lpfnHook = 0
End With
result = GetOpenFileName(fb)
If result <> 0 Then
fName = Left(fb.lpstrFile, InStr(fb.lpstrFile, vbNullChar) - 1)
End If
End Sub
poi ho preparato un pulsante con questo codice:
Dim fName As String
Dim fb As OPENFILENAME6
Call ShowFile3(Me, fb)
fName = Left(fb.lpstrFile, InStr(fb.lpstrFile, vbNullChar) - 1) 'percorso completo
[Forms]![formMail2]![Testo12] = fName