Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
916to920
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
916to920
916to920
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Problem mit .Execute

Problem mit .Execute
23.10.2007 16:32:00
Hein
hello again,
mittels untenstehendem Skrypt versuche ich vor dem Öffnen des Files zu prüfen ob dieses überhaupt existiert. Nun ist mir aufgefallen dass das Skrypt trotz eines vorangestellten "_" (underscore-Zeichen) davon ausgeht dass das File vorhanden ist.
Die Prüfung sollte jedoch nur bei einer EXAKTEN Übereinstimmung weiterfahren, ansonsten sollte er auf 'else' springen.
Hat da jemand eine Erklärung?
Gruss aus Zürich
Hein
  • 
    Public Sub file_exist()
    Dim company_name As String
    Dim isin_name As String
    Dim path_name As String
    Dim file_name_e As String
    Dim file_name_d As String
    i = 2
    Do Until IsEmpty(Cells(i, 1).Value)
    company_name = Cells(i, 1).Value
    isin_name = Cells(i, 2).Value
    path_name = Cells(i, 3).Value
    file_name_e = Cells(i, 4).Value
    file_name_d = Cells(i, 5).Value
    With Application.FileSearch
    .NewSearch
    .LookIn = path_name
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    .Filename = file_name_e
    If .Execute > 0 Then
    Dim objWd As Object
    Set objWd = CreateObject("Word.Application")
    With objWd
    .Visible = True
    .Documents.Open path_name & file_name_e
    End With
    Else
    Cells(i, 1).EntireRow.Interior.ColorIndex = 3
    End If
    End With
    i = i + 1
    Loop
    End Sub
    


  • 3
    Beiträge zum Forumthread
    Beiträge zu diesem Forumthread

    Betreff
    Datum
    Anwender
    Anzeige
    AW: Problem mit .Execute
    23.10.2007 18:30:10
    Tino
    Hallo,
    versuche es mal mit dieser Version.
    
    Public Sub file_exist()
    Dim company_name As String
    Dim isin_name As String
    Dim path_name As String
    Dim file_name_e As String
    Dim file_name_d As String
    Dim i As Variant
    i = 2
    Do Until IsEmpty(Cells(i, 1).Value)
    company_name = Cells(i, 1).Value
    isin_name = Cells(i, 2).Value
    path_name = Cells(i, 3).Value
    file_name_e = Cells(i, 4).Value
    file_name_d = Cells(i, 5).Value
    With Application.FileSearch
    .NewSearch
    .LookIn = path_name
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    .Filename = file_name_e
    If .Execute > 0 Then
    For i = 1 To .FoundFiles.Count
    If .FoundFiles(i) = path_name & file_name_e Then
    Exit For
    End If
    GoTo nichtdabei:
    Next i
    Dim objWd As Object
    Set objWd = CreateObject("Word.Application")
    With objWd
    .Visible = True
    .Documents.Open .FoundFiles(i).Name
    End With
    Else
    nichtdabei:
    Cells(i, 1).EntireRow.Interior.ColorIndex = 3
    End If
    End With
    i = i + 1
    Loop
    End Sub
    


    Gruss Tino

    Das Forum lebt von Rückmeldungen!


    Anzeige
    AW: Problem mit .Execute
    24.10.2007 09:13:00
    Hein
    Guten Morgen
    Danke für deine Rückmeldung, leider funktioniert das bei mir nicht so richtig. Ich erhalte die Fehlermeldung
    'Object doesn't support this property or method', der Debugger markiert nachstehende Zeile gelb:
    .Documents.Open .FoundFiles(i)
    Gruss aus Zürich
    Heini

    AW: Problem mit .Execute
    24.10.2007 09:49:00
    Tino
    Hallo,
    ja, weil Application.FileSearch durch dass neue With objWd aufgehoben ist.
    so müsste es gehen.
    
    Public Sub file_exist()
    Dim company_name As String
    Dim isin_name As String
    Dim path_name As String
    Dim file_name_e As String
    Dim file_name_d As String
    Dim i As Variant
    i = 2
    Do Until IsEmpty(Cells(i, 1).Value)
    company_name = Cells(i, 1).Value
    isin_name = Cells(i, 2).Value
    path_name = Cells(i, 3).Value
    file_name_e = Cells(i, 4).Value
    file_name_d = Cells(i, 5).Value
    With Application.FileSearch
    .NewSearch
    .LookIn = path_name
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    .Filename = file_name_e
    If .Execute > 0 Then
    For i = 1 To .FoundFiles.Count
    If .FoundFiles(i) = path_name & file_name_e Then
    Exit For
    End If
    GoTo nichtdabei:
    Next i
    Dim objWd As Object
    Set objWd = CreateObject("Word.Application")
    With objWd
    .Visible = True
    .Documents.Open Application.FileSearch.FoundFiles(i)
    End With
    Else
    nichtdabei:
    Cells(i, 1).EntireRow.Interior.ColorIndex = 3
    End If
    End With
    i = i + 1
    Loop
    End Sub
    


    Gruss
    Tino

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Anzeige