Hallo Leute,
gibt es die Möglichkeit via AutoIT zu prüfen, ob Excel auf dem PC installiert ist?
Besten Dank im Voraus!
Viele Grüße,
Dino
Hallo Leute,
gibt es die Möglichkeit via AutoIT zu prüfen, ob Excel auf dem PC installiert ist?
Besten Dank im Voraus!
Viele Grüße,
Dino
Danke - die zwei Zeilen waren es
water: In einem Verzeichnis möchte ich nur bei den Dateien (xls) die mit "ZET_" beginnen incl. Unterverzeichnisse VBA-Passwort entfernen.
Geht das auch per AutoIT? Datei für Datei öffnen, mit dem VBA-Passwort "managmentTOX2015" entsperren, Datei speichern, nächste Datei abarbeiten, die mit "ZET_" beginnt.
Besten Dank!
Dino
Mit _FileListToArrayRec einen Array mit allen Dateien befüllen. Dann in einer Schleife den Array abarbeiten und mit $oWorkbook = _Excel_BookOpen öffnen und das Passwort als Parameter mitgeben. Dann mit $oWorkbook.Password = "" das Passwort entfernen und die Datei mit _Excel_BookSave zurückschreiben.
Vorher natürlich eine Sicherung der Dateien erstellen!
Folgender Code ist ungetestet. Kopiere ein paar Dateien/inklusive Unterverzeichnisse in ein neues Verzeichnis und setze $sFilePath auf dieses neue Verzeichnis.
Nachdem der Code durchgelaufen ist, bitte prüfen, ob die Passwort weg sind.
Der Code enthält keine Fehlerprüfungen.
#include <File.au3>
#include <Excel.au3>
$oExcel = _Excel_Open(False) ; Open Excel hidden
$sFilePath = "..." ; <== Change this line
$aFiles = _FileListToArrayRec($sFilePath, "ZET_*.xls", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
For $i = 1 to $aFiles[0]
$oWorkbook = _Excel_BookOpen($oExcel, $aFiles[$i], False, True, "managmentTOX201")
$oWorkbook.Password = ""
_Excel_BookSave($oWorkbook)
_Excel_BookClose($oWorkbook)
Next
_Excel_Close($oExcel)
Alles anzeigen
Das Passwort ist nicht weg.
Die Datei wurden schon im Hintergrund geöffnet. Zum Verständnis: Es eght um das VBA-Passwort im ALT+F11 Visual Basic Editor, den ich aufheben möchte.
Zum Verständnis: Es eght um das VBA-Passwort im ALT+F11 Visual Basic Editor, den ich aufheben möchte.
Aus meiner Sicht gibt es für Excel 2 Passworte:
Habe gerade kein Office verfügbar, daher sagt mir das Alt+F11 Passwort nichts. Wird das benötigt um eingebettetes VBA zu lesen/ändern?
Es gibt noch ein drittes VBA-Passwort. Es wird benötigt um VBA zu lesen/ändern?
Wie Du sieht, ist das nicht ganz einfach.
Aus Deinem Link ist zuerst einmal die Zeile:
wichtig um das Passwortfenster zu öffnen.
In AutoIt sollte es wie folgt aussehen:
Die FindControl Methode wird hier beschrieben: https://msdn.microsoft.com/en-us/library/…office.11).aspx
Kannst Du bitte in einem kurzen Testscript Excel starten, das Workbook öffnen und obige Zeile ausführen. Kommt dann das Passwort-Fenster?
Hi water,
getestet - Passwort-Fenster wird angezeigt.
Super,
dann kannst Du das Fenster mit "normalen" AutoIt-Mitteln (WinWait, ControlSend, ControlClick etc.) bearbeiten.
#include <File.au3>
#include <Excel.au3>
$oExcel = _Excel_Open(False)
$sFilePath = "D:\excel_template\daten"
$aFiles = _FileListToArrayRec($sFilePath, "ZET_*.xls", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
For $i = 1 to $aFiles[0]
$oWorkbook = _Excel_BookOpen($oExcel, $aFiles[$i])
_DeleteVBASave()
_Excel_BookSave($oWorkbook)
_Excel_BookClose($oWorkbook)
Next
_Excel_Close($oExcel)
Func _DeleteVBASave()
$oExcel.VBE.CommandBars(1).FindControl(Default, 2578, Default, Default, True).Execute
Local $iCount = 0
Do
$iCount += 1
Sleep(50)
Until WinExists("VBAProject Kennwort") Or $iCount = 100
If WinActivate("VBAProject Kennwort", "") Then
ControlSetText ("VBAProject Kennwort", "", '[CLASS:Edit; INSTANCE:1]', "test") ;Kennwort
Sleep(100)
ControlClick("VBAProject Kennwort", "","Button1") ;OK
WinWait("VBAProject - Projekteigenschaften", "")
WinActivate("VBAProject - Projekteigenschaften", "")
ControlCommand("VBAProject - Projekteigenschaften", "", "[CLASS:SysTabControl32; INSTANCE:1]", "TabRight", "")
Sleep(100)
ControlClick("VBAProject - Projekteigenschaften", "Projekt sperren","Button2") ;Projekt für die Anzeige sperren
Sleep(100)
ControlSetText ("VBAProject - Projekteigenschaften", "", '[CLASS:Edit; INSTANCE:1]', "") ;Kennwort
Sleep(100)
ControlSetText ("VBAProject - Projekteigenschaften", "", '[CLASS:Edit; INSTANCE:2]', "") ;Kennwort bestätigen
Sleep(100)
ControlClick("VBAProject - Projekteigenschaften", "","Button4") ;OK
Else
WinWait("VBAProject - Projekteigenschaften", "")
WinActivate("VBAProject - Projekteigenschaften", "")
ControlClick("VBAProject - Projekteigenschaften", "","Button2") ;OK
EndIf
EndFunc
Alles anzeigen
Schaut gut aus
Eigentlich sollte es auch möglich sein, alle Schritte innerhalb des VBE automatisiert über das Objekt auszuführen. Da der Schutz für VBA-Projekte mit Kennwort erst ab Office 200n eingeführt wurde, kann ich das jedoch nicht nachvollziehen (ich arbeite noch immer sehr zufrieden mit Office 2000).
Es scheint aber notwendig die Bibliothek 'VBIDE' einzubinden. Das ist immer projektbezogen. Ich habe mal eine Funktion erstellt, die die Bibliothek einbindet und gleichzeitig die TopLevel-Referenz für das VBE-Objekt zurückgibt.
Um Zugriff auf die richtigen Controls zu erlangen auch noch eine Debug-Funktion, die alle Menübänder und deren Controls ausliest.
Vielleicht hilft das weiter.
$sApplicationType = "Excel.Application"
$oApp = ObjGet("", $sApplicationType)
If Not IsObj($oApp) Then Exit MsgBox(262192, "Fehler", "Die Projektbibliothek kann nur bei einer geöffneten Datei hinzugefügt werden!")
; VBIDE-Bibliothek einbinden und Referenz auf VBE-TopLevel-Objekt holen
$oVBE = _VBIDE_Add($oApp)
; um Zugriff auf die richtigen Ctrl zu bekommen, alle Menübänder mit Auflistung Ctrl-ID, Ctrl-Bezeichnung in Konsole ausgeben
__DEBUG_COMMANDBARS($oVBE)
Func __DEBUG_COMMANDBARS($_oVBE)
Local $sOutput = '', $s5 = ' ', $s30 = ' '
Local $oCmdBars = $_oVBE.CommandBars()
For $oBar In $oCmdBars
$sOutput &= StringFormat('== MENÜ - NAME: %s == NAME LOCAL: %s == VISIBLE: %s ==%s', _
StringLeft($oBar.Name & $s30, 30), StringLeft($oBar.NameLocal & $s30, 30), StringLeft($oBar.Visible & $s30, 5), @LF)
For $ctrl In $oBar.Controls
$sOutput &= StringFormat(' CONTROL ID: %s CAPTION: %s%s', StringLeft($ctrl.ID & $s5, 5) , $ctrl.Caption, @LF)
Next
Next
ConsoleWrite($sOutput)
EndFunc
; gibt gleichzeitig das TopLevel-Objekt des VisualBasicEditors zurück
Func _VBIDE_Add($_oApp)
If Not IsObj($_oApp) Then Return SetError(1,0,MsgBox(48,"Fehler","Keine Anwendungsdatei geöffnet!"))
Local $fFound = False
; Auflistung der verfügbaren Verweise nach "VBIDE" durchsuchen
Local $oVBE = $_oApp.VBE
For $Ref In $oVBE.ActiveVBProject.References
If $Ref.Name = 'VBIDE' Then
$fFound = True
ExitLoop
EndIf
Next
; wenn Bibliothek noch nicht enthalten, diese hinzufügen
If Not $fFound Then $oVBE.ActiveVBProject.References.AddFromGuid("{0002E157-0000-0000-C000-000000000046}", 5, 3)
Return $oVBE
EndFunc
; entfernt die Bibliothek wieder vom Projekt
Func _VBIDE_Remove($_oApp)
If Not IsObj($_oApp) Then Return SetError(1,0,MsgBox(48,"Fehler","Keine Anwendungsdatei geöffnet!"))
For $Ref In $_oApp.VBE.ActiveVBProject.References
If $Ref.Name = 'VBIDE' Then Return $_oApp.VBE.ActiveVBProject.References.Remove('VBIDE')
Next
EndFunc
Alles anzeigen
EDIT:
Das Menüband mit CommandBars(1) auszuwählen halte ich für zu unsicher. Wenn man es nur am eigenen PC braucht und der Index passt, geht das sicher in Ordnung. Aber mehr Sicherheit bringt der Zugriff über den String. Wie der lautet lässt sich ja mit meiner Debug-Funktion abfragen.
Vielleicht auch ganz brauchbar, der Zugriff auf Elemente nur über Namen von Menüband und Control:
[autoit]
;~ Bsp.: Öffnen Objektkatalog
_VBIDE_CtrlRun($oVBE, 'Voreinstellung', 'Objektkatalog')
[/autoit][autoit][/autoit][autoit]Func _VBIDE_CtrlRun($_oVBE, $_sCmdBar, $_sCtrl)
$_oVBE.CommandBars($_sCmdBar).Controls($_sCtrl).Execute
EndFunc