title image


Smiley Re: System-Verzeichnisbaum mit vorgegebenem Verzeichnis per A97 öffnen?
Wenn du eine Datei in einem vorgegebenen Verzeichnis suchen oder speichern willst würde ich dir meine Filse-Save-Dialog-Klasse empfehlen wenn du dir davon eine Instanz erzeugt hast kanns du unter anderem auch das Attribut für den Startpfad setzen.greetings Stephan***************************************************Ich beantworte keine Fragen per Email.***************************************************Option Compare DatabaseOption ExplicitPrivate 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 StringEnd TypePrivate Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As BooleanPrivate Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _ Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As BooleanPrivate Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As LongConst ahtOFN_READONLY = &H1Const ahtOFN_OVERWRITEPROMPT = &H2Const ahtOFN_HIDEREADONLY = &H4Const ahtOFN_NOCHANGEDIR = &H8Const ahtOFN_SHOWHELP = &H10Const ahtOFN_NOVALIDATE = &H100Const ahtOFN_ALLOWMULTISELECT = &H200Const ahtOFN_EXTENSIONDIFFERENT = &H400Const ahtOFN_PATHMUSTEXIST = &H800Const ahtOFN_FILEMUSTEXIST = &H1000Const ahtOFN_CREATEPROMPT = &H2000Const ahtOFN_SHAREAWARE = &H4000Const ahtOFN_NOREADONLYRETURN = &H8000Const ahtOFN_NOTESTFILECREATE = &H10000Const ahtOFN_NONETWORKBUTTON = &H20000Const ahtOFN_NOLONGNAMES = &H40000' New for Windows 95Const ahtOFN_EXPLORER = &H80000Const ahtOFN_NODEREFERENCELINKS = &H100000Const ahtOFN_LONGNAMES = &H200000Dim flReadOnly As Boolean, flOverwritePrompt As Boolean, flHideReadOnly As Boolean, flNoChangeDir As Boolean, flShowHelp As BooleanDim flNovalidate As Boolean, flAllowMultiselect As Boolean, flExtensionDifferent As Boolean, flPathMustExist As Boolean, flFileMustExist As BooleanDim flCreatePrompt As Boolean, flShareAware As Boolean, flNoReadOnlyReturn As Boolean, flNotestFileCreate As BooleanDim flNoLongNames As Boolean, flExplorer As Boolean, flNoDereferenceLinks As Boolean, flLongNames As Boolean, flNoNetworkButton As BooleanDim strFilters As String, strDialogTitle As String, blnSaveDialog As Boolean, strStartDir As String, lngFilterIndex As Long, strFileName As StringPrivate Sub Class_Initialize()flReadOnly = FalseflOverwritePrompt = TrueflHideReadOnly = TrueflNoChangeDir = FalseflShowHelp = TrueflNovalidate = FalseflAllowMultiselect = FalseflExtensionDifferent = FalseflPathMustExist = TrueflFileMustExist = TrueflCreatePrompt = FalseflShareAware = FalseflNoReadOnlyReturn = FalseflNotestFileCreate = FalseflNoLongNames = FalseflExplorer = FalseflNoDereferenceLinks = FalseflLongNames = FalseflNoNetworkButton = FalsestrFilters = ahtAddFilterItem(strFilters, "Alle Dateien (*.*)", "*.*")strDialogTitle = "Wählen Sie eine Datei zum Öffnen"blnSaveDialog = FalsestrStartDir = "C:\"lngFilterIndex = 1strFileName = ""End SubProperty Let FLGoverwritePrompt(op As Boolean)flOverwritePrompt = opEnd PropertyProperty Let FLGhideReadOnly(hro As Boolean)flHideReadOnly = hroEnd PropertyProperty Let FLGnoChangeDir(ncd As Boolean)flNoChangeDir = ncdEnd PropertyProperty Let FLGshowHelp(sh As Boolean)flShowHelp = shEnd PropertyProperty Let FLGnoValidate(nv As Boolean)flNovalidate = nvEnd PropertyProperty Let FLGallowMultiselect(am As Boolean)flAllowMultiselect = amEnd PropertyProperty Let FLGextensionDifferent(ed As Boolean)flExtensionDifferent = edEnd PropertyProperty Let FLGpathMustExist(pme As Boolean)flPathMustExist = pmeEnd PropertyProperty Let FLGfileMustExist(fme As Boolean)flFileMustExist = fmeEnd PropertyProperty Let FLGcreatePrompt(cp As Boolean)flCreatePrompt = cpEnd PropertyProperty Let FLGshareAware(sa As Boolean)flShareAware = saEnd PropertyProperty Let FLGnoReadOnlyReturn(nror As Boolean)flNoReadOnlyReturn = nrorEnd PropertyProperty Let FLGnoTestFileCreate(nfc As Boolean)flNotestFileCreate = nfcEnd PropertyProperty Let FLGnoNetworkButton(nnb As Boolean)flNoNetworkButton = nnbEnd PropertyProperty Let FLGnoLongNames(nln As Boolean)flNoLongNames = nlnEnd PropertyProperty Let FLGexplorer(e As Boolean)flExplorer = eEnd PropertyProperty Let FLGnoDereferenceLinks(ndl As Boolean)flNoDereferenceLinks = ndlEnd PropertyProperty Let FLGlongNames(ln As Boolean)flLongNames = lnEnd PropertyProperty Let FLGreadOnly(ro As Boolean)flReadOnly = roEnd PropertyProperty Let dialogTitle(dt As String)strDialogTitle = dtEnd PropertyProperty Let startDir(sd As String)strStartDir = sdEnd PropertyProperty Let filterIndex(fi As Long)lngFilterIndex = fiEnd PropertyProperty Let saveDialog(sd As Boolean) blnSaveDialog = sdEnd PropertyProperty Let defaultFileName(dfn As String)strFileName = dfnEnd PropertyProperty Get FLGreadOnly() As BooleanFLGreadOnly = flReadOnlyEnd PropertyProperty Get FLGoverwritePrompt() As BooleanFLGoverwritePrompt = flOverwritePromptEnd PropertyProperty Get FLGhideReadOnly() As BooleanFLGhideReadOnly = flHideReadOnlyEnd PropertyProperty Get FLGnoChangeDir() As BooleanFLGnoChangeDir = flNoChangeDirEnd PropertyProperty Get FLGshowHelp() As BooleanFLGshowHelp = flShowHelpEnd PropertyProperty Get FLGnoValidate() As BooleanFLGnoValidate = flNovalidateEnd PropertyProperty Get FLGallowMultiselect() As BooleanFLGallowMultiselect = flAllowMultiselectEnd PropertyProperty Get FLGextensionDifferent() As BooleanFLGextensionDifferent = flExtensionDifferentEnd PropertyProperty Get FLGpathMustExist() As BooleanFLGpathMustExist = flPathMustExistEnd PropertyProperty Get FLGfileMustExist() As BooleanFLGfileMustExist = flFileMustExistEnd PropertyProperty Get FLGcreatePrompt() As BooleanFLGcreatePrompt = flCreatePromptEnd PropertyProperty Get FLGshareAware() As BooleanFLGshareAware = flShareAwareEnd PropertyProperty Get FLGnoReadOnlyReturn() As BooleanFLGnoReadOnlyReturn = flNoReadOnlyReturnEnd PropertyProperty Get FLGnoTestFileCreate() As BooleanFLGnoTestFileCreate = flNotestFileCreateEnd PropertyProperty Get FLGnoNetworkButton() As BooleanFLGnoNetworkButton = flNoNetworkButtonEnd PropertyProperty Get FLGnoLongNames() As BooleanFLGnoLongNames = flLongNamesEnd PropertyProperty Get FLGexplorer() As BooleanFLGexplorer = flExplorerEnd PropertyProperty Get FLGnoDereferenceLinks() As BooleanFLGnoDereferenceLinks = flNoDereferenceLinksEnd PropertyProperty Get FLGlongNames() As BooleanFLGlongNames = flLongNamesEnd PropertyProperty Get dialogTitle() As StringdialogTitle = strDialogTitleEnd PropertyProperty Get saveDialog() As BooleansaveDialog = blnSaveDialogEnd PropertyProperty Get startDir() As StringstartDir = strStartDirEnd PropertyProperty Get filterIndex() As LongfilterIndex = lngFilterIndexEnd PropertyProperty Get defaultFileName() As StringdefaultFileName = strFileNameEnd PropertyPrivate Function buildFlags() As LongIf flReadOnly = True Then buildFlags = buildFlags Or ahtOFN_READONLYIf flOverwritePrompt = True Then buildFlags = buildFlags Or ahtOFN_OVERWRITEPROMPTIf flHideReadOnly = True Then buildFlags = buildFlags Or ahtOFN_HIDEREADONLYIf flNoChangeDir = True Then buildFlags = buildFlags Or ahtOFN_NOCHANGEDIRIf flShowHelp = True Then buildFlags = buildFlags Or ahtOFN_SHOWHELPIf flNovalidate = True Then buildFlags = buildFlags Or ahtOFN_NOVALIDATEIf flAllowMultiselect = True Then buildFlags = buildFlags Or ahtOFN_ALLOWMULTISELECTIf flExtensionDifferent = True Then buildFlags = buildFlags Or ahtOFN_EXTENSIONDIFFERENTIf flPathMustExist = True Then buildFlags = buildFlags Or ahtOFN_PATHMUSTEXISTIf flFileMustExist = True Then buildFlags = buildFlags Or ahtOFN_FILEMUSTEXISTIf flCreatePrompt = True Then buildFlags = buildFlags Or ahtOFN_CREATEPROMPTIf flShareAware = True Then buildFlags = buildFlags Or ahtOFN_SHAREAWAREIf flNoReadOnlyReturn = True Then buildFlags = buildFlags Or ahtOFN_NOREADONLYRETURNIf flNotestFileCreate = True Then buildFlags = buildFlags Or ahtOFN_NOTESTFILECREATEIf flNoLongNames = True Then buildFlags = buildFlags Or ahtOFN_NOLONGNAMESIf flExplorer = True Then buildFlags = buildFlags Or ahtOFN_EXPLORERIf flNoDereferenceLinks = True Then buildFlags = buildFlags Or ahtOFN_NODEREFERENCELINKSIf flLongNames = True Then buildFlags = buildFlags Or ahtOFN_LONGNAMESIf flNoNetworkButton = True Then buildFlags = buildFlags Or ahtOFN_NONETWORKBUTTONEnd FunctionFunction addFilterItem(strDescription As String, Optional strFileType As String)strFilters = ahtAddFilterItem(strFilters, strDescription, strFileType)End FunctionFunction resetFilter()strFilters = ""End FunctionFunction showFileDialog() As StringIf blnSaveDialog = True Then If strDialogTitle = "Wählen Sie eine Datei zum Öffnen" Then strDialogTitle = "Datei speichern unter" End IfEnd IfshowFileDialog = ahtCommonFileOpenSave(buildFlags, strStartDir, strFilters, lngFilterIndex, , strFileName, strDialogTitle, , Not blnSaveDialog)End FunctionPrivate Function TestIt() Dim strFilter As String Dim lngFlags As Long strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _ "*.MDA;*.MDB") strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF") strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT") strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*") MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _ Filter:=strFilter, filterIndex:=3, Flags:=lngFlags, _ dialogTitle:="Hello! Open Me!") ' Since you passed in a variable for lngFlags, ' the function places the output flags value in the variable. Debug.Print Hex(lngFlags)End FunctionPrivate 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 StringDim lngFlags As LongDim 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, _ "Access (*.mdb)", "*.MDB;*.MDA") ' 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 = varFileNameEnd FunctionPrivate Function ahtCommonFileOpenSave( _ Optional ByRef Flags As Variant, _ Optional ByVal InitialDir As Variant, _ Optional ByVal Filter As Variant, _ Optional ByVal filterIndex As Variant, _ Optional ByVal DefaultExt As Variant, _ Optional ByVal fileName As Variant, _ Optional ByVal dialogTitle As Variant, _ Optional ByVal Hwnd As Variant, _ Optional ByVal OpenFile As Variant) As Variant' This is the entry point you'll use to call the common' file open/save dialog. The parameters are listed' below, and all are optional.'' In:' Flags: one or more of the ahtOFN_* constants, OR'd together.' InitialDir: the directory in which to first look' Filter: a set of file filters, set up by calling' AddFilterItem. See examples.' FilterIndex: 1-based integer indicating which filter' set to use, by default (1 if unspecified)' DefaultExt: Extension to use if the user doesn't enter one.' Only useful on file saves.' FileName: Default value for the file name text box.' DialogTitle: Title for the dialog.' hWnd: parent window handle' OpenFile: Boolean(True=Open File/False=Save As)' Out:' Return Value: Either Null or the selected filenameDim OFN As tagOPENFILENAMEDim strFileName As StringDim strFileTitle As StringDim fResult As Boolean ' Give the dialog a caption title. If IsMissing(InitialDir) Then InitialDir = CurDir If IsMissing(Filter) Then Filter = "" If IsMissing(filterIndex) Then filterIndex = 1 If IsMissing(Flags) Then Flags = 0& If IsMissing(DefaultExt) Then DefaultExt = "" If IsMissing(fileName) Then fileName = "" If IsMissing(dialogTitle) Then dialogTitle = "" If IsMissing(Hwnd) Then Hwnd = Application.hWndAccessApp If IsMissing(OpenFile) Then OpenFile = True ' Allocate string space for the returned strings. strFileName = Left(fileName & String(256, 0), 256) strFileTitle = String(256, 0) ' Set up the data structure before you call the function With OFN .lStructSize = Len(OFN) .hWndOwner = Hwnd .strFilter = Filter .nFilterIndex = filterIndex .strFile = strFileName .nMaxFile = Len(strFileName) .strFileTitle = strFileTitle .nMaxFileTitle = Len(strFileTitle) .strTitle = dialogTitle .Flags = Flags .strDefExt = DefaultExt .strInitialDir = InitialDir ' Didn't think most people would want to deal with ' these options. .hInstance = 0 .strCustomFilter = "" .nMaxCustFilter = 0 .lpfnHook = 0 'New for NT 4.0 .strCustomFilter = String(255, 0) .nMaxCustFilter = 255 End With ' This will pass the desired data structure to the ' Windows API, which will in turn it uses to display ' the Open/Save As Dialog. If OpenFile Then fResult = aht_apiGetOpenFileName(OFN) Else fResult = aht_apiGetSaveFileName(OFN) End If ' The function call filled in the strFileTitle member ' of the structure. You'll have to write special code ' to retrieve that if you're interested. If fResult Then ' You might care to check the Flags member of the ' structure to get information about the chosen file. ' In this example, if you bothered to pass in a ' value for Flags, we'll fill it in with the outgoing ' Flags value. If Not IsMissing(Flags) Then Flags = OFN.Flags ahtCommonFileOpenSave = TrimNull(OFN.strFile) Else ahtCommonFileOpenSave = vbNullString End IfEnd FunctionPrivate Function ahtAddFilterItem(strFilter As String, _ strDescription As String, Optional varItem As Variant) As String' Tack a new chunk onto the file filter.' That is, take the old value, stick onto it the description,' (like "Databases"), a null character, the skeleton' (like "*.mdb;*.mda") and a final null character. If IsMissing(varItem) Then varItem = "*.*" ahtAddFilterItem = strFilter & _ strDescription & vbNullChar & _ varItem & vbNullCharEnd FunctionPrivate Function TrimNull(ByVal strItem As String) As StringDim intPos As Integer intPos = InStr(strItem, vbNullChar) If intPos > 0 Then TrimNull = Left(strItem, intPos - 1) Else TrimNull = strItem End IfEnd Function

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: