PDA

Vollständige Version anzeigen : msgbox-problem


dmsman
02.07.2001, 16:10
hi,
wie kann ich folgende msgbox in vba verwenden ? code:
MsgBox "Sie haben folgendes Dokument ausgewählt: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=6, Flags:=lngFlags, _
DialogTitle:="Dokument-Auswahl")
-----------------------------------------
ahtCommonFileOpenSave ist eine funktion die die ausgewählte datei mit Pfad in der msgbox anzeigt!
ich will jetzt aber beispielsweise so eine msgbox haben:
vorher funktion aufrufen die dialog aufruft für datei auswählen:
----------------------
ahtCommonFileOpenSave
dim ant as string
ant = msgbox ("Datei: $var übernehmen?",vbyesno)
------------------------------------
doch dieser code funktioniert nicht ganz wie geb ich den die variable an? hier ist noch der auszug aus meinem modul mit der funktion:
Option Compare Database
Option Explicit

'***************** Code Start **************
' code opens a dialog for selecting files of any typ
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 SelectDoku()
Dim strFilter As String
Dim lngFlags As Long
Dim var, ant As String

var = CurrentUser()

'strFilter ruft wieder eine Funktion namens ahtAddFilterItem auf
If var = "Admin" Then
strFilter = ahtAddFilterItem(strFilter, "Text Dateien (*.exe)", "*.EXE")
strFilter = ahtAddFilterItem(strFilter, "Text Dateien (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "Word Dateien (*.doc)", "*.DOC")
strFilter = ahtAddFilterItem(strFilter, "Excel Dateien (*.xls)", "*.XLS")
strFilter = ahtAddFilterItem(strFilter, "Access Dateien (*.mda, *.mdb)", "*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "MP3 Dateien (*.mp3)", "*.MP3")
strFilter = ahtAddFilterItem(strFilter, "Zip Dateien (*.zip)", "*.ZIP")
strFilter = ahtAddFilterItem(strFilter, "Alle Dateien (*.*)", "*.*")

MsgBox "Sie haben folgendes Dokument ausgewählt: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=6, Flags:=lngFlags, _
DialogTitle:="Dokument-Auswahl")

End If
Else 'Filter für die Standarduser
strFilter = ahtAddFilterItem(strFilter, "Text Dateien (*.exe)", "*.EXE")
strFilter = ahtAddFilterItem(strFilter, "Text Dateien (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "Word Dateien (*.doc)", "*.DOC")
strFilter = ahtAddFilterItem(strFilter, "Excel Dateien (*.xls)", "*.XLS")
strFilter = ahtAddFilterItem(strFilter, "Access Dateien (*.mda, *.mdb)", "*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "Alle Dateien (*.*)", "*.*")
MsgBox "Sie haben folgendes Dokument ausgewählt: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=6, Flags:=lngFlags, _
DialogTitle:="Dokument-Auswahl")
End If
Debug.Print Hex(lngFlags)

End Function


Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
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
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 filename
Dim OFN As tagOPENFILENAME
Dim strFilename As String
Dim strFileTitle As String
Dim 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 If
End Function


'************** Code End *****************


so genug code für heute hoffentlich kann mich einer nachvollziehen!nochmal in kurzform
ich will
eine funktion starten,
diese liefert mir dateinamen mit pfadangabe,will in msgbox nur dateinamen ausgeben und abfragen !
danke

Stefan Kulpa
02.07.2001, 17:55
<font face="Verdana" size="2">Hallo,

am einfachsten ist es, den kompletten Pfad zu "zerlegen"; Beispiel:</font>

<PRE><FONT SIZE=1 FACE=Courier New> <FONT COLOR=#000080>Dim</FONT> sFilePath <FONT COLOR=#000080>As String</FONT>
<FONT COLOR=#000080>Dim</FONT> sFilename <FONT COLOR=#000080>As String</FONT>
<FONT COLOR=#000080>Dim</FONT> sFolder <FONT COLOR=#000080>As String</FONT>
<FONT COLOR=#000080>Dim</FONT> lOffset <FONT COLOR=#000080>As</FONT> <FONT COLOR=#000080>Long</FONT>

<FONT COLOR=#008000>'** Beispielpfad:</FONT>
sFilePath = "D:\Eigene Dateien\Dokumente\Word\MyData.doc"
<FONT COLOR=#008000>'** Letzten Backslash ermitteln</FONT>
lOffset = InStrRev(sFilePath, "\") <FONT COLOR=#008000>'(ab VBA 6!!!)</FONT>
sFolder = Left$(sFilePath, lOffset - 1)
sFilename = Mid$(sFilePath, lOffset + 1)
<FONT COLOR=#008000>'** Testausgabe:</FONT>
<FONT COLOR=#000080>Debug.Print</FONT> "Ordner: "; sFolder
<FONT COLOR=#000080>Debug.Print</FONT> "Datei: "; sFilename

</FONT></PRE>

<font face="Verdana" size="2">HTH</font>

<hr><font face="Verdana" size="2"><font color="#008000"><a href="http://vbtipps.gmxhome.de/MyLinks.html" target="_blank">Hier könnte man auch was finden ...</a></font></font>