Daten von ProTool an Excel

Larry Laffer

Super-Moderator , User des Jahres 2008-2009
Teammitglied
Beiträge
15.146
Reaktionspunkte
3.629
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo,
in einer ProTool-Applikation von mir übergebe ich Mess-Daten zur Archivierung an Excel. Das VB-Script dazu sieht so aus :

Code:
[COLOR=#0000ff]Dim[/COLOR] appExcel , wsExcel , wbExcel , QDatei
[COLOR=#0000ff]Dim[/COLOR] i , f , w
[COLOR=#0000ff]Dim[/COLOR] a , e
[COLOR=#0000ff]Dim[/COLOR] Org 
[COLOR=#0000ff]Dim[/COLOR] wMin , wMax , wMittel
[COLOR=#008000]' Pointer auf Tabelle laden[/COLOR]
[COLOR=#0000ff]Set[/COLOR] appExcel = CreateObject ("EXCEL.Application")
QDatei = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"Info: Verzeichnis MessDaten"[/COLOR] + "Messung.xls"
[COLOR=#0000ff]Set[/COLOR] wbExcel = appExcel.Workbooks.Open (QDatei)
[COLOR=#0000ff]Set[/COLOR] wsExcel = wbExcel.Worksheets("Daten")
[COLOR=#008000]' Tabellen-Eckdaten ausfüllen[/COLOR]
wbExcel.Author = "Anlage 170"
wsExcel.Range("D2") = Now 
[COLOR=#ff0000]Messdaten_Datei[/COLOR] = "Messung " +_
Right(Year(Now) ,2) +_
Right(100 + Month(Now) ,2) +_
Right(100 + Day(Now) ,2) +_
" - " +_
Right(100 + Hour(Now) ,2) +_
Right(100 + Minute(Now) ,2) +_
Right(100 + Second(Now) ,2) +_
" .xls"
wsExcel.Range("C6") = [COLOR=#ff0000]Kurve_Anz_Einträge[/COLOR] 
 
wsExcel.Range("A2") = [COLOR=#ff0000]Par_KW_Artikel_Nummer[/COLOR]
[COLOR=#0000ff]If[/COLOR] [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 Auswertung_IO"[/COLOR] [COLOR=#0000ff]Then[/COLOR] wsExcel.Range("B4") = "IO"
[COLOR=#0000ff]If[/COLOR] [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 Auswertung_NIO"[/COLOR] [COLOR=#0000ff]Then[/COLOR] wsExcel.Range("B4") = "NIO"
wsExcel.Range("C10") = [COLOR=#ff0000]Par_KW_Höhe[/COLOR]
wsExcel.Range("C11") = [COLOR=#ff0000]Par_KW_Höhe_Toleranz[/COLOR] 
wsExcel.Range("C13") = [COLOR=#ff0000]Par_KW_Weg_1[/COLOR]
wsExcel.Range("C14") = [COLOR=#ff0000]Par_KW_Weg_1_F[/COLOR]
wsExcel.Range("C15") = [COLOR=#ff0000]Par_KW_Weg_1_F_Toleranz[/COLOR]
wsExcel.Range("C17") = [COLOR=#ff0000]Par_KW_Weg_2[/COLOR]
wsExcel.Range("C18") = [COLOR=#ff0000]Par_KW_Weg_2_F[/COLOR]
wsExcel.Range("C19") = [COLOR=#ff0000]Par_KW_Weg_2_F_Toleranz[/COLOR]
wsExcel.Range("C21") = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 akt.Messwert Höhe"[/COLOR]
wsExcel.Range("C23") = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 akt.Messwert F1 (L1)"[/COLOR]
wsExcel.Range("C24") = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 akt.Messwert F2 (L2)"[/COLOR]
wsExcel.Range("C26") = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 Abweichung max."[/COLOR]
wsExcel.Range("C27") = [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"St.211 Abweichung min."[/COLOR]
[COLOR=#008000]' Werte-Tabelle übernehmen[/COLOR]
Org = wsExcel.Range("B4")
[COLOR=#0000ff]For[/COLOR] i = 1 [COLOR=#0000ff]To[/COLOR] 100
wsExcel.Cells(i +1, 5) = [COLOR=#ff0000]Kurve_Messwerte_Federkraft[/COLOR] (i) / 10
wsExcel.Cells(i +1, 6) = [COLOR=#ff0000]Kurve_Messwerte_Weg[/COLOR] (i) / 10
wsExcel.Cells(i +1, 7) = [COLOR=#ff0000]Kurve_Messwerte_kumuliert[/COLOR] (i) / 10
[COLOR=#0000ff]Next[/COLOR]
 
[COLOR=#008000]' Tabelle abspeichern[/COLOR]
wbExcel.Saveas [COLOR=#ff0000]PtVar[/COLOR].[COLOR=#ff0000]"Info: Verzeichnis MessDaten"[/COLOR] + [COLOR=#ff0000]Messdaten_Datei[/COLOR] ,[COLOR=#0000ff]true[/COLOR]
wbExcel.Close [COLOR=#0000ff]false[/COLOR]
[COLOR=#008000]' verwendeten Speicher wieder freigeben[/COLOR]
[COLOR=#0000ff]Set[/COLOR] appExcel = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] wsExcel = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] wbExcel = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] QDatei = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] i = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] f = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] w = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] a = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] e = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] Org = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] wMin = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] wMax = [COLOR=#0000ff]Nothing[/COLOR]
[COLOR=#0000ff]Set[/COLOR] wMittel = [COLOR=#0000ff]Nothing[/COLOR]

Das Ganze klappt auch, aber nicht zuverlässig. Wenn ich es häufiger aufrufe, dann stürzt mir ProTool irgendwann ab. Kann jemand einen Fehler erkennen ?
Ich könnte mir vorstellen, dass Excel irgendwelche Speicherbereiche nicht wieder freigibt ...
 
Hallo Larry.

Kannst du vielleicht zu .csv schreiben, anstatt Excel direkt zu benutzen.
Das Schreiben zu .csv funktioniert ohne schwierigkeiten für mich.
Und du kannst die .csv-Datei in Excel öffnen.

Wie oft sollen die Daten geloggt werden ?
 
Zuletzt bearbeitet:
Zuviel Werbung?
-> Hier kostenlos registrieren
OPEN EXCEL -> Set appExcel = CreateObject ("EXCEL.Application")
OPEN BOOK -> Set wbExcel = appExcel.Workbooks.Open (QDatei)
CREATE SHEET -> Set wsExcel = wbExcel.Worksheets("Daten")
SAVE BOOK -> wbExcel.Saveas
CLOSE BOOK -> wbExcel.Close false

(Missing) CLOSE EXCEL -> appExcel.Quit()

Change order to release objects
Set wsExcel = Nothing
Set wbExcel = Nothing
Set appExcel = Nothing

 
Hallo,
genau das wars :
Code:
[COLOR=#0000ff](Missing) CLOSE EXCEL -> appExcel.Quit()[/COLOR]

Danke nochmals für die Unterstützung ...
Thanks for your assistance ...
 
@JesperMP :
Ich schreibe die Daten (im Augenblick) nur auf Anforderung in das Excel-Sheet. Es kann aber sein, dass es zyklisch werden muss (alle 3 - 4 Sekunden). Ich könnte natürlich auch mit einer *.csv-Datei arbeiten, aber so ist es schon eleganter ...


Weitere Frage :
Kann man die Variable "appExcel" auch als ProTool-Variable übergeben ?
Wenn ja, dann würde ich diese beim Start der Visu zuweisen und beim Beenden wieder schliessen ...
 
Zurück
Oben