Thema Datum  Von Nutzer Rating
Antwort
12.01.2022 07:13:43 ch79
NotSolved
12.01.2022 11:20:34 ralf_b
NotSolved
12.01.2022 11:28:49 ch79
NotSolved
12.01.2022 12:13:41 ralf_b
NotSolved
12.01.2022 13:17:51 Gast31643
NotSolved
12.01.2022 13:38:06 ralf_b
NotSolved
12.01.2022 14:41:05 ch79
NotSolved
12.01.2022 15:22:01 ralf_b
NotSolved
Rot VBA, 2 Dateipfade für Ordnersuche in Makro
12.01.2022 16:54:54 ch79
NotSolved
12.01.2022 17:43:15 ralf_b
NotSolved
13.01.2022 16:46:14 ch79
Solved
12.01.2022 12:15:41 ralf_b
NotSolved
13.01.2022 11:05:05 Gast31131
NotSolved
13.01.2022 16:44:48 ch79
NotSolved

Ansicht des Beitrags:
Von:
ch79
Datum:
12.01.2022 16:54:54
Views:
869
Rating: Antwort:
  Ja
Thema:
VBA, 2 Dateipfade für Ordnersuche in Makro

Die Änderung habe ich gesehen und ausmarkiert. Funktioniert leider trotzdem nicht. Kann es auch daran liegen das nicht beide Pfade gleich aufgebaut sind?

sPath1 = "L:\01_Projekte_#\01_Auftragsordner_#\"
 sPath2 = "\\10.10.100.0\Exchange\Projekte_#\"

Beim ersten sucht er ja nach dem entsprechenden Jahr zur Ablage ab, was beim 2. entfällt. Da gibt es nur den Exchangeordner und dann den Projektordner.

Wie würde das Makro aussehen wen ich nur mit Pfad 2 arbeite?

 

Option Explicit

Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
    ByVal DirPath As String) As Long

Public Sub SaveSpecial()
   Dim sPath1 As String, sPath2 As String
  
 sPath1 = "L:\01_Projekte_#\01_Auftragsordner_#\"
 sPath2 = "\\10.10.100.0\Exchange\Projekte_#\"
   
  Call SaveSpecial_mod(sPath1)
  Call SaveSpecial_mod(sPath2)
  
End Sub
Public Sub SaveSpecial_mod(sPath As String)
 
'Const FOLDER_PATH As String = "L:\01_Projekte_#\01_Auftragsordner_#\"
 
    Dim lngYear As Long, lngReturn As Long
    Dim strFolder As String, strSubFolder As String, strValue As String, strFile As String
    Dim blnFound As Boolean
 
    strValue = Split(Cells(2, 10).Text, "-")(0)
    strFile = Cells(2, 10).Text
 
    For lngYear = Year(Date) - 1 To Year(Date) + 1
 
        strFolder = Replace(sPath, "#", CStr(lngYear))

        'strFolder = Replace(FOLDER_PATH, "#", CStr(lngYear))

        lngReturn = MakeSureDirectoryPathExists(strFolder)

        If lngReturn = 0 Then

            Call MsgBox("Ordner kann nicht erstellt werden.", vbCritical, "Dateisystemfehler")
            Exit Sub

        Else

            strSubFolder = Dir$(strFolder & strValue & "*", vbDirectory)

            If strSubFolder <> vbNullString Then

                If InStr(1, ThisWorkbook.Name, "_") = 0 Then
                    strFile = strFile & "_" & ThisWorkbook.Name
                Else
                    strFile = strFile & Mid$(ThisWorkbook.Name, InStr(1, ThisWorkbook.Name, "_"))
                End If

                Call ThisWorkbook.SaveAs(Filename:=strFolder & strSubFolder & "\" & _
                    strFile, FileFormat:=xlOpenXMLWorkbookMacroEnabled)
                blnFound = True
                Exit For

            End If
        End If
    Next

    If Not blnFound Then _
        Call MsgBox("Ordner ''" & strValue & "'' nicht gefunden.", _
        vbCritical, "Datei nicht gespeichert")

End Sub


 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
12.01.2022 07:13:43 ch79
NotSolved
12.01.2022 11:20:34 ralf_b
NotSolved
12.01.2022 11:28:49 ch79
NotSolved
12.01.2022 12:13:41 ralf_b
NotSolved
12.01.2022 13:17:51 Gast31643
NotSolved
12.01.2022 13:38:06 ralf_b
NotSolved
12.01.2022 14:41:05 ch79
NotSolved
12.01.2022 15:22:01 ralf_b
NotSolved
Rot VBA, 2 Dateipfade für Ordnersuche in Makro
12.01.2022 16:54:54 ch79
NotSolved
12.01.2022 17:43:15 ralf_b
NotSolved
13.01.2022 16:46:14 ch79
Solved
12.01.2022 12:15:41 ralf_b
NotSolved
13.01.2022 11:05:05 Gast31131
NotSolved
13.01.2022 16:44:48 ch79
NotSolved