C
#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