Thema Datum  Von Nutzer Rating
Antwort
Rot Datein eines Ordners oeffnen und bearbeiten
16.03.2016 12:00:49 Julianq234
Solved
16.03.2016 12:02:20 Gast90883
NotSolved
17.03.2016 18:27:22 Frank
NotSolved

Ansicht des Beitrags:
Von:
Julianq234
Datum:
16.03.2016 12:00:49
Views:
1143
Rating: Antwort:
 Nein
Thema:
Datein eines Ordners oeffnen und bearbeiten
Hallo, ich versuche mich gerade an folgender Aufgabenstellung: Alle .csv Datein eines ausgewaehlten Ordners oeffnen und dann das dann nach XXXProgramXXstartsXXXX startende Programm abspulen fuer jede Datei. Danach die Datein nicht schliessen oder speichern. Leider bekomme ich keinen runtime error (1004). Hat jemand eine Idee? Meine VBA-Kenntnisse sind leider noch sehr uebersichtlich. Vielen Dank!


<div>

Sub LoopAllExcelFilesInFolder()</div><div>
</div><div>Dim wb As Workbook</div><div>Dim myPath As String</div><div>Dim myFile As String</div><div>Dim myExtension As String</div><div>Dim FldrPicker As FileDialog</div><div>
</div><div>'Optimize Macro Speed</div><div>&nbsp; Application.ScreenUpdating = False</div><div>&nbsp; Application.EnableEvents = False</div><div>&nbsp; Application.Calculation = xlCalculationManual</div><div>
</div><div>'Retrieve Target Folder Path From User</div><div>&nbsp; Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)</div><div>
</div><div>&nbsp; &nbsp; With FldrPicker</div><div>&nbsp; &nbsp; &nbsp; .Title = "Select A Target Folder"</div><div>&nbsp; &nbsp; &nbsp; .AllowMultiSelect = False</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If .Show <> -1 Then GoTo NextCode</div><div>&nbsp; &nbsp; &nbsp; &nbsp; myPath = .SelectedItems(1) & "\"</div><div>&nbsp; &nbsp; End With</div><div>
</div><div>'In Case of Cancel</div><div>NextCode:</div><div>&nbsp; myPath = myPath</div><div>&nbsp; If myPath = "" Then GoTo ResetSettings</div><div>
</div><div>'Target File Extension (must include wildcard "*")</div><div>&nbsp; myExtension = "*.csv"</div><div>
</div><div>'Target Path with Ending Extention</div><div>&nbsp; myFile = Dir(myPath & myExtension)</div><div>
</div><div>'Loop through each Excel file in folder</div><div>&nbsp; Do While myFile <> ""</div><div>&nbsp; &nbsp; 'Set variable equal to opened workbook</div><div>&nbsp; &nbsp; &nbsp; Set wb = Workbooks.Open(Filename:=myPath & myFile)</div><div>&nbsp; &nbsp;&nbsp;</div><div>'XXXXXXXXXXXXXXXXXXXXProgramXXstartsXXXXXXXXXXXXXXXXXXXXXXXXX</div><div>Dim i As Integer</div><div>Dim j</div><div>
</div><div>i = 0</div><div>j = 0</div><div>
</div><div>&nbsp; &nbsp; Columns("A:A").Select</div><div>&nbsp; &nbsp; Application.CutCopyMode = False</div><div>&nbsp; &nbsp; Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; :=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True</div><div>
</div><div>For i = 19 To 522</div><div>
</div><div>
</div><div>&nbsp;' &nbsp; &nbsp; &nbsp; If &nbsp;Then</div><div>&nbsp;' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rows(i).Delete</div><div>&nbsp;' &nbsp; &nbsp; &nbsp; End If</div><div>
</div><div>&nbsp; &nbsp; If Cells(i, 4).Value >= Cells(i, 5).Value And Cells(i, 4).Value <= Cells(i, 6).Value Or Cells(i, 4).Value = "0" Or Cells(i, 7).Value = "-" Or Cells(i, 7).Value = "mm" Or Cells(i, 4).Value = "Value" Or Cells(i, 7).Value = "mbar" Or Cells(i, 7).Value = "Grad" Or Cells(i, 7).Value = "ccm/min" Or Cells(i, 6).Value = "" Or Cells(i, 5).Value = "" Or Cells(i, 2).Value = "OP1200OS" Or Cells(i, 2).Value = "OP1200CS" Then</div><div>&nbsp; &nbsp; 'Range(Cells(i, 1), Cells(i, 8)).Interior.Color = RGB(0, 255, 0)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Rows(i).Delete</div><div>&nbsp; &nbsp; &nbsp;' Or Cells(i, 4).Value = "1.3" &nbsp; Or Cells(i, 6).Value = "" &nbsp;Or Cells(i, 5).Value = "" &nbsp; &nbsp;Or Cells(i, 7).Value = "kN" &nbsp; Or Cells(i, 7).Value = "Nm"</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; Else</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; Range(Cells(i, 1), Cells(i, 8)).Interior.Color = RGB(255, 0, 0)</div><div>&nbsp; &nbsp; i = i + 1</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;End If</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;i = i - 1</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; ' &nbsp; &nbsp; &nbsp;If Range(Cells(i, 1), Cells(i, 8)).Interior.Color = RGB(0, 255, 0) Or Cells(i, 5).Value = "" Or Cells(i, 6).Value = "" Or Cells(i, 7).Value = "-" Or Cells(i, 4).Value = "Value" Then</div><div>&nbsp; &nbsp;'</div><div>&nbsp; &nbsp; ' &nbsp; &nbsp;End If</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;j = Cells(i, 1).Value</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;If j = "time" Then Exit Sub</div><div>&nbsp; &nbsp;If j = 0 Then Exit Sub</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;</div><div>Next i</div><div>
</div><div>'XXXXXXXXXXXXXXXXXXXXProgramXXendsXXXXXXXXXXXXXXXXXXXXXXXXX</div><div>
</div><div>&nbsp; &nbsp; 'Get next file name</div><div>&nbsp; &nbsp; &nbsp; myFile = Dir</div><div>&nbsp; Loop</div><div>
</div><div>'Message Box when tasks are completed</div><div>&nbsp; MsgBox "Task Complete!"</div><div>
</div><div>ResetSettings:</div><div>&nbsp; 'Reset Macro Optimization Settings</div><div>&nbsp; &nbsp; Application.EnableEvents = True</div><div>&nbsp; &nbsp; Application.Calculation = xlCalculationAutomatic</div><div>&nbsp; &nbsp; Application.ScreenUpdating = True</div><div>
</div><div>End Sub</div><div>
</div>
 

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
Rot Datein eines Ordners oeffnen und bearbeiten
16.03.2016 12:00:49 Julianq234
Solved
16.03.2016 12:02:20 Gast90883
NotSolved
17.03.2016 18:27:22 Frank
NotSolved