Hallo,
die folgende Schleife, welche kontrolliert ob der Dateiname schon vorahnden ist wird nur einmal durchlaufen.
Danach bekomme ich eine Laufzeitfehler 91 in Bezug auf objFSO.FileExists(strDatei) ?
Public Function DateiVorhanden(strDatei As String)
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDatei) = True Then
DateiVorhanden = True
Else
DateiVorhanden = False
End If
Set objFSO = Nothing
End Function
Private Sub CommandButton22_Click()
START:
'No-option email sending
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim datum As Date
Dim inpt As Long
Dim Fehler1 As String
Dim strDatei As String
datum = Now()
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
strDatei = Empty
Set objFSO = Nothing
inpt = Empty
EINGABE1:
On Error GoTo ERRORHANDLER1
inpt = InputBox("Bitte hier kurze Dateinamenerweiterung wie eine Nummer eingeben, Danke", "Dateinamenzustaz", "1")
strDatei = (Environ("TEMP") & "\" & "TBM-Aufgabe-" & Application.UserName & "-" & inpt & ".docx")
If objFSO.FileExists(strDatei) = True Then GoTo ERRORHANDLER1 Else GoTo EINGABE2
If inpt = "Falsch" Then GoTo START Else GoTo EINGABE2
ERRORHANDLER1:
MsgBox "Dateinamen mit dieser Erweiterung existiert schon!"
GoTo START
EINGABE2:
End Sub
Gruß und Danke, Markus
|