Brauche Hilfe bei

  • Hallo zusammen!

    Ich brauche eure Hilfe. Ich würde gerne den Arrays nach und nach mit Excel öffnen lassen, und in ein PDF umwandeln lassen. Wie kann ich das in der Funktion convert umsetzen?

    Ich denke mit einer for to Schleife, aber ich habe das Problem, dass ich nicht weiß, wie ich das umsetzen kann. Ich versteh nicht, wie ich bei _ExcelBookOpen( ) die Arrays nach und nach ansprechen kann, weil so wie es jetzt ist, macht das Script immer alles mit der ersten Datei (aFiles[2])

    Ich hoffe, ihr versteht, wo mein Problem liegt!?

    Vielen Dank

    Gruß Sirius

    Spoiler anzeigen


    Func oeffnen()
    Global $code = FileOpenDialog("Wähle XLSX oder XLS Datei aus!",@StartupDir, "(*.xlsx;*.xls)",1 + 4)

    If @error Then Exit
    Global $aFiles = StringSplit($code, "|", 1)

    For $i = 2 To UBound($aFiles) -1
    $aFiles[$i] = $aFiles[1] & "\" & $aFiles[$i]
    Next
    _ArrayDisplay($aFiles)

    EndFunc

    Func convert()

    For $i = $aFiles[2] to $aFiles[0] Step 1

    Local $oExcel = _ExcelBookOpen($aFiles[2])
    Local $vSheet = 1
    MsgBox("","",$aFiles[2])
    If @error = 1 Then
    MsgBox(0, "Fehler!", "Das Excel-Objekt konnte nicht erstellt werden.")
    Exit
    ElseIf @error = 2 Then
    MsgBox(0, "Fehler!", "Die Datei existiert nicht.")
    Exit
    EndIf
    _ExcelSheetActivate($oExcel, $vSheet)
    $NewFilepath = $aFiles[2]
    $fileformat = 57

    With $oExcel
    .Application.DisplayAlerts = False
    .ActiveWorkBook.SaveAs($NewFilepath, $Fileformat)
    EndWith

    msgbox(0,"Done","Die Datei wurde in PDF convertiert")
    Sleep(50)
    _ExcelBookClose($oExcel, 1)
    Sleep(50)
    ProcessClose("excel.exe")
    Local $PID = ProcessExists("excel.exe")
    If $PID Then ProcessClose($PID)
    Next

    EndFunc

    Einmal editiert, zuletzt von Sirius (9. Februar 2014 um 19:46)

  • 1. Verwende bitte zusätzlich zum Spoiler zukünftig auch den BB-Code für Autoit Quellcode
    2. Ich denke ein Blick ins Array Tutorial von Bugfix würde dir nicht schaden: http://www.bug-fix.info/array_tut.htm
    3. Nun zu deinem Code... du sprichst immer nur die erste Datei des Arrays an ($aFiles[2]), du musst schon auch dein $i der Schleife nutzen, wie du es ja bereits richtig in der Funktion oeffnen() machst.

    Hier die geänderte Version:

    Spoiler anzeigen
    [autoit]


    Func oeffnen()
    Global $code = FileOpenDialog("Wähle XLSX oder XLS Datei aus!",@StartupDir, "(*.xlsx;*.xls)",1 + 4)

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Exit
    Global $aFiles = StringSplit($code, "|", 1)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 2 To UBound($aFiles) -1
    $aFiles[$i] = $aFiles[1] & '\' & $aFiles[$i]
    Next
    _ArrayDisplay($aFiles)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func convert()

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 2 to $aFiles[0]

    [/autoit] [autoit][/autoit] [autoit]

    Local $oExcel = _ExcelBookOpen($aFiles[$i])
    Local $vSheet = 1
    MsgBox("","",$aFiles[$i])
    If @error = 1 Then
    MsgBox(0, "Fehler!", "Das Excel-Objekt konnte nicht erstellt werden.")
    Exit
    ElseIf @error = 2 Then
    MsgBox(0, "Fehler!", "Die Datei existiert nicht.")
    Exit
    EndIf
    _ExcelSheetActivate($oExcel, $vSheet)
    $NewFilepath = $aFiles[$i] & ".pdf"
    $fileformat = 57

    [/autoit] [autoit][/autoit] [autoit]

    With $oExcel
    .Application.DisplayAlerts = False
    .ActiveWorkBook.SaveAs($NewFilepath, $Fileformat)
    EndWith

    [/autoit] [autoit][/autoit] [autoit]

    msgbox(0,"Done","Die Datei wurde in PDF convertiert")
    Sleep(50)
    _ExcelBookClose($oExcel, 1)
    Sleep(50)
    ProcessClose("excel.exe")
    Local $PID = ProcessExists("excel.exe")
    If $PID Then ProcessClose($PID)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]