ich will Excel aufrufen und, wenn Excel 2007 gestartet ist, ein dort enthaltenes VBA-Makro starten.
Wie kann ich dies tun?
Thx
Mike

Das geht sicherlich mit COMatePLUS. Beispiele für Excel sind mit dabei, und es gibt auch diverse in diesem sowie im englischen PB-Forum.Mike32 hat geschrieben:Wie kann ich die drei Schritte (Excel starten mit bestimmter Datei öffnen, Wert eintragen, Makro starten) ausführen? - Also ohne Maus, sondern per Befehl.
Code: Alles auswählen
Sub Sortiere()
'
' Sortiere Makro
'
'
Range("A1:B16").Select
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Tabelle1").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Tabelle1").Sort
.SetRange Range("A1:B16")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Code: Alles auswählen
Sub Starte()
Call Sortiere
End Sub
Mike32 hat geschrieben:1. Dem Benutzer soll aufgelistet werderden, welche Makros sich in der Datei befinden
Code: Alles auswählen
XIncludeFile "COMatePLUS.pbi" ; Anpassen!
EnableExplicit
Define oExcel.COMateObject
Define oWorkbook.COMateObject
Define oCodeModule.COMateObject
Define VBComponentsCount
Define VBComponentsCounter
Define CodeModuleCountOfLines
Define LineCounter
Define.s ProcOfLine, OldProcOfLine
oExcel = COMate_CreateObject("Excel.Application")
If oExcel
oWorkbook = oExcel\GetObjectProperty("Workbooks\Open('DeineMappe.xls')") ; Anpassen!
If oWorkbook
VBComponentsCount = oWorkbook\GetIntegerProperty("VBProject\VBComponents\Count")
; Debug COMate_GetLastErrorDescription()
; wenn: Programmatischer Zugriff auf das Office VBA-Projekt wird verweigert
; dann: http://support.microsoft.com/kb/282830/DE
For VBComponentsCounter = 0 To VBComponentsCount - 1
If oWorkbook\GetIntegerProperty("VBProject\VBComponents(" + Str(VBComponentsCounter) + ")\Type") = 1 ; Module
oCodeModule = oWorkbook\GetObjectProperty("VBProject\VBComponents(" + Str(VBComponentsCounter) + ")\CodeModule")
If oCodeModule
CodeModuleCountOfLines = oCodeModule\GetIntegerProperty("CountOfLines")
Debug CodeModuleCountOfLines
For LineCounter = 1 To CodeModuleCountOfLines
ProcOfLine = oCodeModule\GetStringProperty("ProcOfLine(" + Str(LineCounter) + ", 0)")
If OldProcOfLine <> ProcOfLine
OldProcOfLine = ProcOfLine
Debug ProcOfLine
EndIf
Next
oCodeModule\Release()
Else
Debug "!oCodeModule"
Debug COMate_GetLastErrorDescription()
EndIf
EndIf
Next
oWorkbook\Release()
Else
Debug "!oWorkbook"
Debug COMate_GetLastErrorDescription()
EndIf
oExcel\Invoke("Quit")
oExcel\Release()
Else
Debug "!oExcel"
Debug COMate_GetLastErrorDescription()
EndIf